Search/Navigation:
Related:
SLAC/EPP/HPS Public
Jefferson Lab/Hall B/HPS Run Wiki
S30XL-LESA/LDMX
...
title | WORK IN PROGRESS |
---|
This page is
...
This page is a detailed primer on how to use Subversion for software development.
...
A revision in SVN is a globally unique number identifying identifier, starting with 'r', that tags the state of the repository at some particular time. Every commit will create a new revision. The revision numbers are numbered sequentially from 1 to however many revisions have been created.
...
These are the settings I use for HPS projects.
No Format |
---|
global-ignores = target *.class *.jar *.diff x.x *.log .classpath .project .settings *.tar.gz .cproject gmon.out *.slcio .dependencies |
...
Here is a full list of these status codes.
...
svn ls some/relative/path/
or
svn ls svn://repo/some/path/
svn up
This command can be used to add files:
svn add rel/path/to/file1 rel/path/to/file2
These will then be pushed to the remote repository when you execute a commit.
Delete files from the repository
This command can be used to delete files:
svn rm rel/path/to/file1 rel/path/to/file2
The deletion will occur when you commit.
To delete files use this command:
svn rm /path/to/file
You also need to perform a commit to delete the files in the repository and not just the local copy.
This command is used to commit your local changes to the repository:
svn commit -m "committing some stuff" [optional/path/to/file1] [optional/path/to/file2]
The list of files or directories to commit is optional, but it is usually a good idea to include it.
svn cp src/dir/or/file target/dir/or/file
svn mkdir path/to/dir
Warning | ||
---|---|---|
| ||
Merging is an advanced operation. Always use '--dry-run' to check the results of the command before actually executing it. And always merge equivalent structure nodes when merging a branch back into the trunk, or you will screw up the trunk. |
Merge a branch into the trunk:
svn merge ^/projects/foo/branches/v01-02-03/ ^/projects/foo/trunk
This is an advanced command so don't use it unless you know what you're doing.
Same command which just prints what would happen:
svn merge ^/projects/foo/branches/v01-02-03/ ^/projects/foo/trunk
After a merge, the changes are made to the local copy and must still be committed, using the usual commit command.
...
The ls command is similar to the equivalent Unix command. It can be used to list directory contents.
This is an example of listing contents of a relative path.
No Format |
---|
svn ls trunk/parent |
This command can also be used with absolute SVN URLs.
No Format |
---|
svn ls svn://svn.freehep.org/hps/java/trunk |
The up command is used to synchronize your local of files and directories with the remote repository.
Assuming you are in a local working directory, this command will pull all updates from the server.
No Format |
---|
svn up . |
The add command is used to add new files to the repository.
No Format |
---|
svn add sandbox/castle.txt |
This command does not actually push the files to the server but schedules this to occur. A commit must be executed in order actually perform the addition of the files.
The command can also be used on directories, in which case the default behavior is that all files under the directory will be added too. (Make sure this is actually what you want before committing!)
Files can be deleted from the repository using the rm command.
No Format |
---|
svn rm sandbox/castle.txt |
Similar to how adding files works, the deletion will not occur until you commit.
In order to update the master copy of any file or directory on the server, a commit must be performed first.
This is an example of committing a local file.
No Format |
---|
svn commit -m "Add castle to sandbox." sandbox/castle.txt |
Though this command can be executed without any arguments, it is a good idea to always list explicitly the files you want to include in your commit. Otherwise, every file which is modified locally will be part of the commit, which you may not want.
Files can be copied so that their revision history is kept.
No Format |
---|
svn cp sandbox/castle.txt sandbox/citadel.txt |
A commit is required to perform this action once it is scheduled.
Moving files or directories is very similar to copying or deleting.
No Format |
---|
svn mv sandbox/castle.txt sandbox/citadel.txt |
This command will schedule a deletion of the first file and an addition of the second, copying the revision history from the first to the second. A commit must be executed to perform this command once it is scheduled.
Warning | ||
---|---|---|
| ||
Making branches is an advanced operation. Ask a knowledgeable individual for advice before doing this for the first time. After branching to make major changes in the code, you should make sure to change your IDE / or editor to use the branch branched node instead of the trunk. |
svn cp m "making a branch" ^/projects/foo/trunk ^/projects/foo/branches/foo-dev
Warning | ||
---|---|---|
| ||
Making tags is an advanced operation. Most general users do not need to make tags, and for Maven projects this is done automatically during the release procedures. Never change a tag once it is made. Should changes be required, the preferred method is making them in the trunk and then making a new tag. |
svn cp -m "making a tag" ^/projects/foo/trunk ^/projects/foo/tags/foo-1.2.3
svn revert path/to/broken/local/file
Warning | ||
---|---|---|
| ||
This command should usually be done by the repository administrator. To have Subversion ignore files in your local copy, see the section above entitle "Global config for ignoring files". |
Files can have properties on them. This can be used to alter the behavior of Subversion.
For instance, this command will cause all files with the .log extension to be ignored in the current directory.
svn propset svn:ignore "*.log" .
Do not EVER checkout an SVN project into another Subversion structure node. This has the potential to create some serious issues when executing Subversion commands, and it will also confuse you.
Do not checkout and modify tags of the code. All changes must be made on branches or the trunk so that the remote repository can be updated. Tags are considered 'frozen' once made.
Be careful when using 'svn add' on a directory, as by default it will add ALL files and subdirectories under that directory, which may not be your intended outcome. (see next item)
...
Branching is actually a special case of copying where a structure node is copied to a new location and then development is performed on this new copy. This is a basic way for developers to "fork" the code in an organized fashion so that any potentially disruption changes are kept isolated from the trunk until the code is made stable and working again.
This is an example of making a branch.
No Format |
---|
svn cp -m "Making a new HPS Java branch for some reason." ^/projects/hps/java/trunk ^/projects/hps/java/branches/hps-java_HPSJAVA-123 |
Note here that we have included 'HPSJAVA-123' in the name as a reference to a relevant JIRA item. (This is just a dummy name. In actuality, it should be a real JIRA item.) This allows someone to understand the purpose of that branch from its name.
Warning | ||
---|---|---|
| ||
Merging is an advanced operation, and should not be done without some forethought. Always use '--dry-run' to check the results of the command before actually executing it. And always merge equivalent structure nodes when merging a branch back into the trunk, or you will screw up the trunk. |
Merging is the process of including changes from one node in the repository into another. After working on a branch, for instance, you will usually at some point want to integrate the changes make on the branch back into the trunk.
Using the above example branch, the following is the equivalent merge operation.
No Format |
---|
svn merge ^/projects/hps/java/branches/hps-java_HPSJAVA-123/ ^/projects/hps/java/trunk |
In general, unless very minor changes were made to the code on the branch, you should always communicate with the other developers about plans for merging and what the state of the trunk will be after the merge is performed.
After a merge, the changes (additions, deletions, etc.) are only made to the local copy and must still be committed, using the usual commit command.
Warning | ||
---|---|---|
| ||
Making tags is an advanced operation. Most general users do not need to make tags, and for Maven projects this is done automatically during the release procedures. Never change a tag once it is made. Should changes be required, the preferred method is making them in the trunk and then making a new tag. |
Creating tags in SVN is actually just another case of copying nodes. In fact, there is no good way to actually make a read-only, fixed copy of the files at any given time in SVN, so tags are essentially a convention and not something that is actually supported! Once a tag is made of the code, it should generally not be modified. (That's what the trunk and branches are for.)
This is a (dummy) example of making a tag of the whole trunk.
No Format |
---|
svn cp -m "Making a bogus tag of the trunk." ^/projects/hps/java/trunk ^/projects/hps/java/tags/hps-java-1.2.3 |
The versions in actual tags within the HPS repository will correspond to releases made using Maven and Jenkins.
Sometimes you may want to revert a local file which will replace it with the equivalent file from the server.
For instance, this command will revert a single local file to its master copy, removing any changes you have made on it locally.
No Format |
---|
svn revert sandbox/castles.txt |
The command will execute immediately unlike an addition or deletion.
You can also revert entire nodes recursively, which will replace all changes in and under that node with the master copy.
No Format |
---|
svn revert sandbox --recursive |
You should be careful when reverting entire nodes, as this will completely clobber any changes you have made.
Using revert results in changes to your local copy that are not recoverable e.g. all your local edits will be removed. So be careful when using this command.
...
...
...
...
When executing more complex commands such as 'svn merge' use the '--dry-run' argument like 'svn --dry-run merge' to see what will happen without the command actually being executed.
Do not be too dependent on the IDE for using Subversion. Make sure to have a compatible SVN command line client available e.g. where the SVN minor version number is the same as your IDE's "connector" version (Eclipse), so that you are able to execute shell commands. This can be a pain to setup properly when using Eclipse, so the preferred method of keeping these tools compatible is installing the version of the connector from Eclipse that matches your existing command line client ( e.g. 1.6, 1.7 etc.).
At the beginning of the work day, do an 'svn up' in order to synchronize your working copy with the repository. This will make sure you do not cause conflicts by modifying a file that someone has already made changes to in the repository.
Do not develop code in your working copy for an extended period of time without committing it, provided of course that checking it in does not cause a compilation or test case failure. This is especially true if there is the possibility that someone else is working on the same file. When possible, prefer checking in your work at the end of each day, or, at a minimum, the end of every week.
If there are files that are always generated by your project's build which should not be put into version control, consider adding these file names to the ignore list for the project's directory, as covered here: http://stackoverflow.com/questions/86049/how-do-i-ignore-files-in-subversion
...