Source Control: Fast Start With Subversion

There are many source control mechanisms in use for all types of projects, large and small. Some tools are much more complex than others and better suited to large distributed teams. However, what about an easy to setup, easy to configure, easy to manage tool that can offer version control for a large number of files without eating a huge amount of storage? Let’s dive in with a simple Subversion (often abbreviated as SVN) install and set up a repository for some local documents.

Simple Installation and Setup
In addition to Subversion being a source repository that is easy to use and manage for very small teams (including just one member), it is very easy to install, setup and configure. Installation is as easy as:
sudo apt-get install subversion
OR
sudo yum install subversion

Now all we need to do is run a command to set up our base repository, again, easily accomplished as follows:
svnadmin create /home/user/svn/project

This will create a repository for your documents called ‘project’ in the /home/user/svn directory (we placed it here since our local user has access to that directory/path, it can be whatever path you choose as long as proper permissions are granted for the users or groups accessing it). By default, our repository is not currently available. We can change the configuration so that it can be accessed using just SVN from a command line, in which case we would add a user name and password in the local configuration files (in this case, located in /home/user/svn/project/conf). However, we are going to allow access to the repository be controlled by system accounts (i.e. those accounts that exist on the system configured for SSH access) in order to maintain security. So, we now simply need to start our server daemon like so:
svnserve -d -r /home/user/svn

Verify Our Repository
Make sure the subversion daemon is running:
ps aux | grep svnserve

Which will return something like:

root 5584 0.0 0.1 109824 1244 ? Ss Feb26 0:18 svnserve -d -r /home/user/svn
tcox 10708 0.0 0.0 5164 784 pts/4 R<+ 13:19 0:00 grep svnserve

Our server is running. We can also see if we can access it by running:
svn list "svn+ssh://hostname/project"

Notice here that we are treating the subversion ‘server’ as a URL that combines the use of the subversion and SSH command line parameters. This is important and must appear in the correct order regardless of the operating system you are using. In this case, we have nothing in the repository, so we will get a prompt to login (using our system credentials) and then nothing will return.

So How Do I Use It?
Let’s add a simple text file to our repository. This will illustrate a number of the commands you will most commonly use from a client perspective:

Check out our repository root (yes it is blank, but the process creates the tracking directory we need called .svn):
svn co "svn+ssh://hostname/project" dirname

After being prompted for your system credentials, the checkout (containing nothing), will complete and we now have a directory called .svn in the current directory. Now let’s create a file:
echo "This is a Test File" > somefile.txt

We have a text file called ‘somefile.txt’ that we can add to our repository. Complete that like so:
svn add somefile.txt

Note that we don’t even have to tell it the server or repository to add the file to. The reason is because all we have done is add this new file to our LOCAL copy of the repository. We have a directory called .svn now that keeps track of all the contents/changes/updates/additions/deletions to our LOCAL copy. This way, we can freely do whatever we need to with our copy and not affect the master copy until we are ready. Now let’s add that file to the master repository, which will import the file and create a revision:
svn update

Again, that special directory keeps track of what server/master repository this local copy belongs to and will update it accordingly. If you go to another machine at this point and re-run a checkout on the root repository, you will get a copy of the file we just added. One more command, let’s change our file. Edit the file we created earlier, add some more text so you know what it says and then save the file. Run an ‘svn update’ as above after and the changes will be copied to the server/master repository. Now we can see the differences in our revisions of the file by performing the following action:
svn diff -r 0:1 somefile.txt

This tells subversion to show you the differences between revision 0 (the initial import of the file into the repository) and revision 1 (where we changed the text and updated the repository). The database itself maintains both versions of the file and can show you differences between two or more revisions at any time.

What Client Should I Use?
Other than the command line, which is available for every platform (Windows, OSX and Linux), there are a couple of ‘gold standard’ SVN clients I would recommend, as follows:

 

    • Windows – Good old TortoiseSVN (Free)
    • Apple OSX – Versions ($39) or svnX (Free)
    • Linux – RapidSVN (Free)

 

Final Thoughts
We have only scratched the surface on the power and flexibility of Subversion. There are many sites and books that cover Subversion in detail, but as you can see, we installed, setup, configured, checked out, added content and changed content on a brand new implementation in less than ten minutes. As always, leave questions or comments below and I will do everything I can to address them. If there are specific questions regarding Subversion, we may do another article covering source control and management in more detail. Good luck and keep track!

0 Comments

Leave a Comment

Login

Welcome! Login in to your account

Remember me Lost your password?

Don't have account. Register

Lost Password

Register