Using subversion


(Difference between revisions)
Jump to: navigation, search
(SSH configuration)
(Quick summary of the commands you need)
Line 19: Line 19:
== Quick summary of the commands you need ==
== Quick summary of the commands you need ==
Excecute the commands on your computer at the directory where your copy of the project is found
List existing projects
List existing projects

Revision as of 15:38, 21 August 2013


SSH configuration

The following configuration allows you to access the subversion server on modb without entering your password all the time. All commands shown hereafter are to be exectuted on your local machine (normally you do not need to work directly in your modb account)

Include the following in your file ~/.ssh/config file (create it if it does not exist):

Host modb gher04
  ForwardAgent yes
  User <your username on modb>

Create a SSH key:

ssh-keygen -t dsa

Copy your SSH key to modb:

ssh-copy-id -i ~/.ssh/ modb

Quick summary of the commands you need

Excecute the commands on your computer at the directory where your copy of the project is found

List existing projects

svn list svn+ssh://

Download a project, for example Gher3D:

svn checkout svn+ssh:// local-directory

If you downloaded the files before, update your local version with the command:

svn update

Edit the files in your local directory. To see changes between local and repository:

svn diff

To add or delete files on the repository, use

svn add filename
svn delete filename

To actually commit these changes on the server, use

svn commit -m "some comments"

For a good tracking of the changes, try to add comments when you do the commit.

Download a project under SVN

To find out which projects are in the subversion repository:

svn list svn+ssh://

If the user-name on the local machine is not the same as on the server you can use something like

svn [command] svn+ssh://

The latest version of DINEOF is hosted at , under the source folder. Follow instructions there to download.

To start working with a code under svn:

svn checkout dineof --username your.username

Once we've finished working on the code, see differences respect to repository version:

svn diff

To upload latest modification to repository:

svn commit -m "comment explaining changes you have made"

The next time we download the latest code, we don't need to make the checkout again, just an update:

svn update

Download a particular revision of a project

If you are interested in a particular revision of a project (let's say, the number 3008), you can use the command checkout with additionnal arguments:

svn checkout svn+ssh://

Make release(s) or branch(es)

These operations simply consists in copying the trunk to a another directory.


The trunk is copied to a directory under tags:

svn copy svn+ssh:// svn+ssh:// -m 'release 1.1'

Subversion stores only differences between files. The command "svn copy" does thus not physically copy the whole repository. To checkout a particular release, we need only to specify its location:

svn co svn+ssh:// projectA


Now the trunk is copied to the directory branch:

svn copy svn+ssh:// \
         svn+ssh:// -m 'MPI version'

To checkout a branch, we need only to specify its location:

svn co svn+ssh:// projectA

When working with multiple branches, it might be useful to checkout everything:

svn co svn+ssh://
A    projectA/trunk
A    projectA/trunk/hello.f90
A    projectA/trunk/Makefile
A    projectA/branches
A    projectA/branches/parallel
A    projectA/branches/parallel/hello.f90
A    projectA/branches/parallel/Makefile
A    projectA/tags
A    projectA/tags/r1.0
A    projectA/tags/r1.0/hello.f90
A    projectA/tags/r1.0/Makefile

File history and differences

As SVN stores the differences between versions of a same file, tracking changes is very easy.

History of a file

Use the command svn log with the name of the file as argument. The log indicates:

  • who modified the file and when it was modified
  • the revision number corresponding to the revision
  • a message explaining the change (the -m 'message for commit' option of svn commit)
$ svn log hello.f90
r10 | abarth | 2008-02-24 18:02:35 +0100 (Sun, 24 Feb 2008) | 1 line 

add a real
r2 | abarth | 2008-02-22 21:57:57 +0100 (Fri, 22 Feb 2008) | 1 line

add some file

Changes on a file

Check the diff command in the SVN bool:

What is the difference between version 10 and 2:

$ svn diff -r 10:2 hello.f90
Index: hello.f90
--- hello.f90   (revision 10)
+++ hello.f90   (revision 2)
@@ -1,7 +1,6 @@
 program hello
  implicit none
  integer :: i
- real :: r

  write(6,*) 'hello world'

If you type only

svn diff hello.f90

the output will be the differences between the last committed version and the version you are working on.

Add options to the diff command

If the tabulations and/or spaces in the file have changed, then the

svn diff

command will yield a long list of differences that you probably don't care about. In this case, you would prefer to use

diff -E -b -w


  • -E : Ignore changes due to tab expansion.
  • -b : Ignore changes in the amount of white space/
  • -w : Ignore all white space.

To force svn to use these optional arguments, the syntax is as follows:

svn diff --diff-cmd diff -x "-E -w -b" -r10:2 hello.f90


svn diff --diff-cmd /usr/bin/diff -x "-E -w -b" -r10:2 hello.f90

Hence it is the --diff-cmd option that allows the user to select the diff command, while the argument placed after the -x are the actual options of the diff command.

Undoing changes

For situations when you want to go back to an older version of a file, the command to use is svn merge, as explained at

The typical steps to follow are:

1. Roll back the changed made:

svn merge -r 3010:3008 svn+ssh://

2. Check the status

svn status
M  file_to_modify

3. Check if the unwanted changes are removed:

svn diff

4. Commit

svn commit -m "Undoing change committed in r3010."

Managing conflicts

Before solving conflicts, the best thing is to try to avoid them. If you know you are going to work on a same projects with other colleagues at the same time, try to work on different files.

If for some reasons you have to face conflicts, the first thing is to consult the SVN book:

Diagnosing conflicts

The conflicts will appear when you use the command

svn update

If you try to commit when a conflict was detected, then the commit will be aborted.

Different possibilities can occur for a given file. If before the name of the file you have

  • U: it means that the file was updated.
  • G: the file was merged, meaning that your modifications and those from the other users were done without any overlap.
  • Conflict discovered in file_name: a conflict has to be solved.

Resolving the conflict

In that case, several options are offered:

  • (p) postpone: the conflict will be resolved later
  • (df) diff-full: show all changes made to merged file
  • (e) edit: change merged file in an editor
  • (mc) mine-conflict: accept my version for all conflicts (same)
  • (tc) theirs-conflict: accept their version for all conflicts (same)
  • (s) show all options.

For ever conflicted file, three extra unversioned files are created in your working copy:

  1. filename.mine
  2. filename.rOLDREV
  3. filename.rNEWREV

Once you have solved the conflict, use the command

svn resolved file_name

and commit the file. The three intermediate files will be removed automatically.

Nested check-outs

An SVN checkout within an SVN checkout from a different repository is possible, using the svn:externals property:

svn propget svn:externals . > /tmp/svn_external

add a line to the file /tmp/svn_external (maybe empty) with the local directory name and the URL:


Update the properties and checkout

svn propset svn:externals  -F /tmp/svn_external .
svn up

Notes and caveats

  • When working over SSH, it is advisable to use keys and ssh-agent to cache your passphrase. Otherwise, Subversion will prompt you to enter your password/passphrase several times when communicating with the server.
  • Avoid using two files with the same name in the same directory using different lower case and upper case letters. This can cause trouble when using SVN on some systems (Windows-Dos).

Change the permissions of a file

For example to set a file permission to executable), do not use

chmod +x filename
svn commit -m 'changed permission'

since no change on the file will be captured by svn. The solution is to use

svn propset svn:executable '*' filename
svn commit -m 'changed permission'


'out of date' error during the commit

The message looks like

Transmitting file data .......svn: Commit failed (details follow):                                  
svn: While preparing 'filename' for commit
svn: File 'filename' is out of date 

Possible solution: use the update command

svn delete filename
svn commit -m 'message'
svn update 
svn add filename
svn commit -m 'another message'

Add only new files to subversion

svn add *

will work but gives warning messages. Another solution is

svn status | grep -v "^.[ \t]*\..*" | grep "^?" | awk '{print $2}' | xargs svn add

which looks for files of which the status is ?


More info

Further documentation on svn:

Personal tools