Tutorials

## SVN HowTo

### How to use Version Control with Subversion (SVN)

Subversion is a free software that allows to manage files and directories on a server. Multiple users can work collaboratively with different versions of the files on the server.

First, start reading the SVN Book.

### SVN Installation

To work with SVN, please install it depending on your operating system:

• Ubuntu: sudo apt-get install subversion
• OpenSuse: sudo zypper install subversion
• Mac: The SVN command line tools are contained in the XCode installer.
• Windows: Use TortoiseSVN!

### SVN Usage

You can develop code and maintain it in the SVN repository in the following way:

Browse the repository online:

Check out a repo from the server to a local directory (via the so called check-out-line):

 svn co url/repo directory


For example:

 svn co http://svn.code.sf.net/p/libsquish/code/trunk checkout-dir


This is called an anonymous checkout, because local changes of the repository cannot be submitted to the server.

Change your working directory to the checkout directory:

 cd checkout-dir


Examine the files in the directory:

 ls -l


If the directory contains an open-source software, we can build the software, for example with the CMake build system:

 cmake . && make


Or the Automake build system

 ./configure && make


This is what you basically can do with an anonymous checkout.

If you do not already have write access to the repo, approach the admin of the SVN server and ask for permission to do so or create your own repository. I recommend sourceforge.net for that purpose.

If you have permissions to modify and check out the repository with a username and password, we can do much more with it:

First we check out a local copy with:

 svn co --username=username --password=password url/repo directory


Now we can modify the repository, for example by creating a file with a plain text editor and adding it to version control:

 emacs filename.txt &


This results in a modified local copy of the repository, but the repository on the server has not changed yet!

To see what actually has changed locally, we tell svn to show a status of the actual directory:

 svn stat -v


Now, the local changes of repository are uploaded by committing the local changes to the server:

 svn commit -m “changes”


This creates a new revision of your code on the server. Versions are numbered sequentially, starting with revision number 1.

To see the status both locally and on the server, we tell svn to show a status again:

 svn stat -v


We may also modify the repository by creating a sub-directory and adding it to version control and committing the changes again:

 mkdir subdir


For each commit you need to provide a comment, the so called commit log or commit message. The best way to specify this message is to type it on the command line after the -m option:

 svn commit -m “commit message”


Each new commit will result in a new version with increasing revision number. This time it’s revision number 2.

Now we modify “filename.txt” with a plain text editor (e.g. emacs) again and show the textual changes with:

 emacs filename.txt &
svn diff


The changes shown by the above command are the differences of your local copy against the latest version on the server.

If you are done with your changes, commit those to the server:

 svn commit -m “another commit message”


Side note: svn stores your password so that you do not need to retype the password arguments every time you commit.

Check and see the corresponding commit log:

 svn log .


To update your local copy with changes others may have committed to the repository:

 svn update


If you are working on a project alone, you do not need to do the latter. But you can work on your code on two or more computers, by checking out a copy on each computer. If you commit changes on one computer, then you need to update those changes on the other computers.

In order to have a recent backup copy of your code on the server and to track the evolution of your code, you should adhere to the following rules:

When working with SVN, there are four main rules of thumb:

• Commit your changes at least once a day!
• Do not commit code that doesn’t compile!
• If it doesn’t compile, fix it!
• Before actually committing it, review your code with “svn diff” and fix what you have forgotten to fix!

That’s it. You are using (sub)version control!

### SVN Usage example

To check out the existing repository hello, which contains the “hello, world!” C example, type those commands in the unix shell:

 # check out repo
svn co svn://schorsch.efi.fh-nuernberg.de/hello hello

# change working directory to repo
cd hello

# show commit log of committed revisions
svn log .

# compile and run hello-world example
gcc hello.c -o hello && ./hello

# modify contents
echo “/* this is a comment */” >> hello.c

# show line by line modifications
svn diff

# show modified files
svn stat -v

…