Search/Navigation:
Related:
SLAC/EPP/HPS Public
Jefferson Lab/Hall B/HPS Run Wiki
S30XL-LESA/LDMX
...
This is intended to serve as a basic introduction to the Subversion source code repository tool. Basic terminology will be provided along with examples of commands.
Subversion uses a file system paradigm for its concepts. So many file system terms like copying, deleting, moving, etc. are similarly applicable to SVN repositories.
Some concepts such as merging have no analog in file system terms.
...
similar to their file system analogs.
version control - the management of changes to code or other files using a central tool or service (Subversion being one example)
...
SVN Repositories may contain many code projects.
These could be are separated by different folders in the repository, usually under the root directory, but potentially in any sub-folder.
No Format |
---|
project1 project2 project3 [etc.] |
Separate projects Each project folder will typically have three directoriessub-folders.
No Format |
---|
project1 trunk branches tags |
trunk should contain the main development branch of the code. Most user commits will happen on trunk.
branches contains folders that are copies of the trunk, or some other folder, made by users; these represent development branches of the code that are eventually merged back into trunk or another branchabandoned.
tags contains copies of the trunk that should not (really ever) be modified; typically, these are made when releasing software versions by a build tool or script.
...
The primary way to interact with a Subversion repository is through the svn command in a command terminal.
You can check if you have this installed on the terminal by typing
Code Block | ||
---|---|---|
| ||
svn |
Should the command not be found, then it would be a good idea to install it.
If you are using Linux, this If you are using Linux or some other Unix this is almost certainly already installed for you by your distro.
Otherwise, you could try installing it (e.g. for Yum users).
Code Block | ||||
---|---|---|---|---|
| ||||
yum install subversion |
You can also use Subversion plugins in IDEs like Eclipse and NetbeansOn OSX, it should be bundled with the Xcode development tools which you can get in the app store.
You will probably want to configure the SVN client to ignore certain types of files that you might have in your working copy but do not want to be visible.
You can add global file patterns that should be ignored to the config file at ~/.subversion/config which should have been created by Subversion in your working directory(if it does not exist then execute the svn command in a terminal).
These are the settings I use for global ignoressome example settings.
No Format |
---|
global-ignores = target *.class *.jar *.diffclasspath x.xproject *.log .classpath .project .settings *.tar.gz .cproject gmon.out *.slcio .dependencies.settings |
The filter will apply when using the status command and ignored files will not be considered by add, etc.The patterns will apply to all SVN nodes so make sure that you really want these patterns to always be ignored in your working copy.
All commands described below assume you are in a terminal using bash on Linux or a similar Unix OS; also, most of these commands assume that the current local directory is working directory in the command terminal represents an SVN structure node that has been checked out of the repository.
Most of the arguments used for these example commands are completely bogus and, depending on the command, should be replaced by valid paths to files in your working copy or the remote repository (should you actually want to execute those commands!).
If you really want to experiment with some of the more advanced commands (branching, merging, copying, etc.) you might think about setting up your own test repository as doing this kind of stuff on an actual production repository if you are just testing or fooling around is not recommended!polite.
Checkout a Folder from SVN
...
No Format |
---|
svn co svn://example.org/repo/some/dir |
svn:// is the protocol ( for talking to communicating with the SVN server).
example.org is the host name of the SVN server.
repo is the name of the SVN repository (SVN Servers servers can have multiple repositories).
some/dir is a folder in the repository.
You could also may checkout the entire repository.
No Format |
---|
svn co svn://example.org/repo/ |
...
No Format |
---|
svn rm rel/path/to/file1 rel/path/to/file2 |
The deletion will occur in the repository when you commit.
When you execute the rm command, Subversion will not by default leave a local copy of the file and so will delete it immediately!
...
This command is used to commit your local changes to the repository, including deletions, changes and additionsadditions which have been done on the working copy.
No Format |
---|
svn commit -m "committing some stuff" path/to/file1 optional/path/to/file2 |
Usually it is good to include a list of files that should be specifically affected by the commit. Otherwise, you may inadvertently commit changes.by the commit. Otherwise, you may inadvertently commit changes.
Files must be explicitly added or deleted in order to be included in a commit using the add or rm sub-commands (described above).
Any changes to files that SVN knows about in the working copy will be included in the commit automatically.
Similar to how a file system works, files can be copied to directories. In Subversion, this will essentially " fork " the file from the source version of it where it can be independently changed.
Here is an example of making a copy of a file with a new name.
...
In both cases, you will need to commit in order for these changes to be pushed to the repository.
Warning | ||
---|---|---|
| ||
Merging is an advanced command. Always use '--dry-run' to check the results of a merge before executing it. |
...
Two different types of merges will be covered here, though this is far from covering all the ways in which this command can be used.
When working on a branch, you will periodically want to merge from trunk to your branch.
No Format |
---|
cd my-hps-java-branch; svn merge ^/java/trunk |
Similarly, you eventually will want to merge back into trunk from the branch once you are done with it.
No Format |
---|
cd hps-java-trunk; svn merge ^/java/branches/my-hps-java-branch |
Merging can also be used to undo bad commits.
See for examples:
http://stackoverflow.com/questions/13330011/how-to-revert-an-svn-commit
This page shows the full syntax for the merge command.
Creating a development branch is done using the copy command to copy the current version of the trunk into a branches folder.
a branch, you will periodically want to merge from trunk to your branch.
No Format |
---|
cd my-hps-java-branch; svn merge ^/java/trunk |
Similarly, you eventually will want to merge back into trunk from the branch once you are done with it.
No Format |
---|
cd hps-java-trunk; svn merge ^ |
No Format |
svn cp -m "Creating development branch." ^/projects/java/trunk ^/projects/java/branches/my-hps-devjava-branch |
This command Merging can also be used to make copies of filesundo bad commits.
No Format |
---|
svn cp -m "Copying my file." myfile.java myfile_v2.java |
See for examples:
http://stackoverflow.com/questions/13330011/how-to-revert-an-svn-commit
This page shows the full syntax for the merge command.
Creating a development branch is done using the copy command to copy the current version of the trunk into a branches Or to copy a file into a folder.
No Format |
---|
svn cp -m "CopyingCreating mydevelopment filebranch." myfile.java some/dir ^/projects/java/trunk ^/projects/java/branches/my-dev-branch |
Now my-dev-branch will be a complete copy of trunk at the time when it was copiedWhen copying a file into a folder, the folder must already exist in the repository (or have been added using the add command).
Tagging is actually performed by using the copy command.
...