Posted September 28, 2009 by Spyros in Linux Tips

How to Configure Subversion Versioning Control System to Manage Your Projects


Subversion is a software version management tool.Practically, this means that if we make project that contains code, we have always the stress that we do something error and we cannot restore previous versions of that code.Moreover, if a lot of individuals working with the same code (they write it at the same time), what will become if they edit a file or code in the same time but in a different way ? A solution would be that one phones the other and says to him what changes he had made, but this seems a bit unpractical, don’t you think? This process is what the versioning control software does, it informs us if something that we need to change has already been edited and keeps versions of the changes that have undergone by the various developers of the project.

In this tutorial, we will be discussing subversion, which i personally feel is the best versioning control software i’ve used.

How to setup a repository

A repository is the place where we keep our projects. SVN creates a central place where we can put our new projects so that they are kept under svn surveillance. For starters, each svn command starts with the word ‘svn’. The first command that a user should run to create a repository is:

svnadmin create /home/thought/svn

This command created a new repository at the /home/thought/svn folder (it’s kinda standar that a repository is created at /etc type folders, but this is an example). There are now 2 commands in order to add files to your repository, svn add and svn import. Hovewer, we first need to create a new project using svn import. Suppose that we have a document named ‘project’ at filepath /home/thought/project and we need to import its contents to our new project. We use this command:

svn import /home/thought/project file:///home/thought/svn/practice -m "Importing Project"

This means that we create a project inside the repository under the name practice. Our repository is ready and till now it works locally in our machine. We can also remove /home/thought/project since our project exists now in our repository’s files.

Retrieve – Checkout files from the repository

Let’s say that we need to retrieve files from our repository. This happens using the command:

svn checkout file:///home/thought/svn/practice new

or the equivalent

svn co file:///home/thought/svn/practice new

We now have the repository’s project in our hard disk under the name ‘new’ in the current working dir. We can now edit the files however we like without any fear of messing with the files and not being able to get the working copy back :)

Subversion – Remote Access

Naturally, there is almost always no need to use subversion locally but remotely probably through the internet or local lan. For this to be done, there are different ways to progress but i’ll be describing the most used one, classic svnserve.

svnserver is actually a server that receives queries at the svn:// protocol by default at port 3690 (don’t forget to port forward if you need to). It’s a daemon and needs to be run constantly and listen, so it’s quite typical to put it into inetd.conf in such a way so that it’s identified by our repository.

svn stream tcp nowait svn /usr/bin/svnserve svn -i -r /home/thought/svn

After we add this line, anyone can checkout using the command (suppose thought.net is my domain) :

svn co svn://thought.net/practice new

Finally, change the permissions of your repository so that the user svn has full access and the rest only write access and edit the file conf/svnserve.conf inside your repository so that it now reads:

auth-access = write
anon-access = none
password-db = passwd

Or change according to what the user permission you need (none,write,read). At the file passwd in the same folder /conf add the following:

user1 = emma
user2 = mary

According to your usernames and what passwords you want them to use.

File changes, receive updates

Each time you change a file in your repository’s project, you need to state that you wish to change a file so that the rest of the developers can see it. This happens this way, if we suppose that there is a file named ‘readme’ inside the repository and we just edited it:

svn commit -m "i changed README file - bug fixes"

This command changes the repository so that it reflects your new changes. If at that point someone has changed the same file, there could probably be a conflict, but it can be reverted since we have the previous versions. The -m switch just sends a message to inform what the edit was about.

In order to retrieve the changes that others have made at the project, you type:

svn update

These are the basic stuff you need to operate subversion. There are many more commands like add, status, log, revert and more that i will hopefully describe in the second part of this tutorial :)