I am currently working on some python coding and since the number of files is getting quite large and being more than one developer on the project it became clear that I need to do some revision control. Eventhough de-centralised revison control is the new black I wanted a centralised solution so everybody could check out agains the server.
Setting up the subversion
First I create the repository
tjansson@ikos:~$ svnadmin create subversion --fs-type fsfs
Then I import the files residing the folder ~/dpy into the repository.
tjansson@ikos:~$ svn import dpy/ file:///home/gfy-1/tjansson/subversion/dpy -m "Initial import"
Now the folder ~/dpy isn’t used anymore as all the files are inside the repository in a database.
All the users I need to colaborate with is users on the same Linux server. Eventhough I really wanted to have grainular control of the user access to the repository this wasn’t possible since the university server doesn’t have ACL (Acces control lists) enabled. The ugly solution is to make the directory writable by all users on the system – which isn’t to bad since I trust the users at this university:
tjansson@ikos:~$ tjansson@ikos:~$chmod -R 777 subversion/
For more information on the subject of permission and repositories:
Supporting Multiple Repository Access Methods
An example of daily usage
Every user that has to work with the files needs to create a working copy and for the sake of the argument I will do the steps as the imaginary user hermann. First hermann get a copy of the files from the repository.
hermann@ikos:~$ svn co file:///home/gfy-1/tjansson/subversion A dpy/geofour-gui.py ... Checked out revision 12.
Now hermann has a woking copy. Now he would like to start working with the files, so first he makes sure that he has the lastest copy of the files:
hermann@ikos:~/dpy$ svn update At revision 12.
Now hermann starts editing the files and when he whishes to commit his changes he uses the command:
hermann@ikos:~/dpy$ svn commit -m "I have change the cheese class to allow emmentaler"
Two thing are important at this point. There should always be a comment and the comment should be informative – this makes it easy to go back to a former change. The second is to commit every time a change has been done – this makes it easy to find points of errors.
The last basic commands is to add a file:
hermann@ikos:~/dpy$ svn add baconcheese.txt hermann@ikos:~/dpy$ svn commit -m "This cheese is important"
and remove a file:
hermann@ikos:~/dpy$ svn remove ham.txt hermann@ikos:~/dpy$ svn commit -m "Ham is not cheese and shouldn't be a part of the project."
Finally It can be nice to see what happened since the last update or commit:
hermann@ikos:~/dpy$ svn log
There are lots off more advanced command such as branching, merging etc. and they are described here:
Version Control with Subversion (Official free book)
Remote acces through SSH
Say I wish to work on the files from home. I can do this through SSH:
tjansson@dirac:~>svn co svn+ssh://ikos.foo.bar/home/gfy-1/tjansson/subversion/dpy firstname.lastname@example.org password: A dpy/geofour-gui.py ... Checked out revision 12.
Adding $Id$ to the files
One of the great thing when using revision control is to be able to keep track on who altered the file and when. This can be done by adding a small tag, $Id$ to the the files. First the files should be prepared to for this by using the following command. In this command I only do this to the python files:
hermann@ikos:~/dpy$ svn propset svn:keywords "Id" *.py
And in the top of the python files I add the line # $Id$ like this:
#!/usr/bin/python # $Id$
which is expanded after the next commit:
#!/usr/bin/python # $Id: covfit-gui.py 8 2008-03-11 15:10:18Z tjansson $
Visual svn clients
Even though it is great to know the basic commands it can be nice to use a graphical user interface to manage SVN. On linux system I use kdesvn which is really nice.
Using SVN on Microsofts Windows
On Windows the standards seems to be a open source explorer plugin called TortoiseSVN which is easy to install. First thing to do is download the latestes version from:
and install the program. Since the program is a explorer plugin Windows needs to be restarted before use.
After a restart the first thing to do is to checkout the repository which is done by creating a folder and right-clicking the folder as shown in this picture.
Now a interface should appear where a line like this should be inserted as seen in the image:
And after a lot password typing – 3 times in my case the locale folder should be updated. The actions as doing a commit or update of the local folder can now be acces on the folder in question by right-clicking the folder as seen in this image