Subversion

September 11, 2009

If you want to maintain a code repository, subversion could satisfy your needs. Creating such a repository is fairly simple. The issues with subversion being not great with branches/tags are well documented. I won’t go into those details.
I will list the steps to create a repository fast and get working on checking in and checking out your code. All the information here is condensed from the Redbook .

1. Create the subversion repository

Say, you want to create a repository under the directory /home/svn/my_repos, this is the command to create the repository.

$ svnadmin create /home/svn/my_repos

That’s it.

2. Get the code base ready

Subversion redbook recommends that the code be in structured in 3 directories: trunk, branches, tags. Say your code has two files main.h, main.c.

Create a top level directory, say my_code

$ mkdir my_code

Create the subversion recommended branches

$ cd my_code
$ mkdir trunk
$ mkdir branches
$ mkdir tags

Copy all your sources to my_code/trunk. You now have your sources ready for importing into the repository.

3. Import the code to your repository

$ svn import my_code file:///home/svn/my_repos -m “Initial import of my_code”

You are done!

4. Check your work

To see the repository, the subversion command svnlook is your friend.

$ svnlook info /home/svn/my_repos

This will dump the last checked in message (in this case the initial message during import) along with the time details

$ svnlook tree /home/svn/my_repos

This will dump your source tree. It will look like this

/
trunk/
main.h
main.c
branches/
tags/

As always svnlook help will enlist other commands

5. Checking out and checking in code

To check your code to your local machine:

$ svn co file:///home/svn/my_repos

This will check out your code to local directory my_local_dir. I am assuming that your repository is on your local machine. This almost will never be the case if you are in a professional environment. You will most likely use tunneling over ssh. To access your code over the tunnel:

$ svn co svn+ssh://svn@hostname/home/svn/my_repos

Checking in your work is pretty simple:

$ svn ci

6. Branching and tagging

Branching and tagging are really copy operations in subversion. Basically it saves a snapshot. It is up to the user to create a branch. Say you want to create a branch from trunk and work on that branch:

$ svn copy /repos_path/trunk /repos_path/branches/branch_name

where branch_name is the name of the branch you want. That’s about it. You can do the usual check in and check out from this branch. Tagging is similar. You just copy to tags directory in the repository.