Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents
maxLevel2
minLevel2

Development with Subversion

This page is a detailed primer on how to use Subversion for software development. It includes definitions of basic terminology plus explanations and examples of basic commands

It includes definitions of basic terminology plus explanations and examples of basic commands.

Subversion Versions

The version of Subversion (no pun intended) is important because older versions are not compatible with newer ones, meaning you cannot checkout a project with say 1.8 and then use a 1.6 client on it.  This is because the metadata formats used to track local files changes with minor release numbers in incompatible ways. 

You can use this command to upgrade your local copy from an older client to the newer one.

No Format
cd sandbox; svn upgrade .

You should also make sure that your IDE's Subversion library is compatible with the command line client (covered in Project Development in Eclipse).

Terminology

Here are some basic terms with which you should be familiar in order to understand the rest of this guide.

...

The Subversion command line client is executed from a shell with the "svn" (note lower-case) command.  (This is not to be confused with SVN in all upper case!)

...

A working copy is your local version of any SVN module or file from the remote repository.  Executing an svn checkout will create a local copy of a file or directorysvn checkout will create a local copy of a file or directory.

master copy

The master copy refers to the current version of a file on the SVN server, as opposed to a local copy on your computer.

commit

Executing a commit will push your changes on to one or more files or directories to the remote repository, making the master copy match your current local copy of those files.

revision

A revision in SVN is a globally unique 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.  (SVN actually tracks revisions globally rather than on a per file basis.)

URL

URLs in SVN are used to identify paths on the remote server which has the master copy of the source code.  In the case of Subversion, these .  These will have svn:// as the protocol.    (SVN supports other protocols as well such as https.)

For example, svn://svn.freehep.org/hps is the URL for the HPS Subversion repository.

...

In general, if you execute svn commands within a local directory that is tracked by Subversion, they will be interpreted correctly.

repository root

The base URL node of the remote repository such as svn://svn.freehep.org/hps/.  This is similar to the root node in a file system.

The "^" character can be used to specify the repository root for any command that accepts a Subversion URL.

...

Any part of the repository under the root.  Structure nodes can be conceptualized as a sub-directory on a file system, with the repository root as the root directory.

tag

This is a copy of some directory the code at a certain point in time like , usually when a release is made.  By convention, a tag should not be modified once created.  They are usually kept in a node called 'tags'.

...

This is a fork of the trunk, or even of another branch, which is for development and can be modified after it is created.  Branches are usually kept in a node called 'branches'.

merge

To merge means combining together two nodes in order to merge their changes togetherMerging will combine together the contents of two nodes.  This usually occurs when a branch should be reintegrated into the trunk or another branch.

revert

To revert means clobbering your local changes in the working copy and replacing them with the current copy from the remote repository.

...

This is an example of listing contents of a relative path.

  

No Format
svn ls trunk/parent

...

No Format
svn ls svn://svn.freehep.org/hps/java/trunk

 

Synchronizing your copy with the remote repository

...

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 The name of the branch is 'HPSJAVA-123' in the name as a reference to a relevant ' to reference a JIRA item.   (This  This is just a dummy name.  In actuality, it should be a real JIRA item. )  This  This allows someone to understand the purpose of that branch from its name.
 

 

Performing a merge

Warning
titleAdvanced Command

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.

...

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.

...

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.

 

Miscellaneous Tips and Warnings

  • Do not checkout SVN URLs into some other project that is already managed by Subversion.  This has the potential to create some serious issues when executing Subversion commands, and it will also confuse you. 
     
  • Do not modify files that are in tags of the code.  All changes should be made on branches or the trunk.  Tags should be 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) 
     
  • Be careful when using svn add and svn commit without any arguments or with directories, either from the command line or from the top-level in your IDE e.g. the infamous Team > Commit from an Eclipse project.  This may cause many files to be added to the repository that should not actually be tracked and will subsequently need to be removed.  Once a file is added, it is tracked "forever" by the repository and cannot be easily deleted, even though it might then be removed in the trunk and subsequent revisions.  So please double check that you are adding only the files which are intended.  Before making a large or complicated commit, first use svn status in your working copy to see what files will be committed or run svn --dry-run commit. 
     
  • When doing complex tasks like merging, use the --dry-run argument like svn --dry-run merge to see what will happen without the command actually being executed.  
  • Do not be overly dependent on your IDE for executing Subversion commands.  Always make sure to have a compatible SVN command line client available. 
     
  • At the beginning of the work day, you should generally do a quick svn up on any modules you will be working on in order to synchronize the working copy with the repository.  This will make sure you do not cause conflicts by modifying a file that someone has already made conflicting 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

...