All about SVN

Subversion (or SVN) is an open source version control system that can be used to maintain several versions of files such as program source codes, webpages, and other documentation. It has several features including most CVS features, versioned copy, delete, renames, etc. Most Linux installations already include SVN so that you can use it immediately if you like.

I started using SVN only recently to track changes I made to the source codes of programs I have written, and hence this note. SVN is quite handy as it allows you to access your source code from any computer which can access your repository. You can commit changes you made to the code in one workstation, and when you work on those codes in another workstation,  you can just update the local copy to reflect the changes you made. In the following, I’ll assume that SVN is already installed.

1. Creating an SVN Repository

[user@mycomp] cd
[user@mycomp] mkdir Repos
[user@mycomp] svnadmin create Repos

First, create a directory which will serve as the SVN repository. In the example above, a directory called Repos/ is created in the user’s home directory (line 2). To tell SVN to use this as the repos, use svnadmin create command passing the directory name as the target (line 3).  After executing this command, SVN will place several directories and files in this directory. You can check the contents of Repos/ by running ls -al Repos.

2. Storing codes into the repository

[user@mycomp] mkdir appwebcam
[user@mycomp] mkdir appwebcam/trunk
[user@mycomp] mkdir appwebcam/logs
[user@mycomp] mkdir appwebcam/branches
[user@mycomp] mkdir appwebcam/trunk/SRC
[user@mycomp] mkdir appwebcam/trunk/bin

Now that you have your repository setup, it is time to add some data into it. You can structure the data within the repository any way you like. But usually, you’ll have a main directory for a project (say, appwebcam/), then within this, you have subdirectories for trunk/, logs/, and branches/. Within the trunk/ subdirectory, you can have SRC/ subdirectory to hold your source codes, bin/ subdirectory for the binaries, etc. Lines 1-6 simply create this directory structure.

3. Import your codes to the repository

[user@mycomp] svn import ./appwebcam file:///home/user/Repos/appwebcam -m "Initial import"
Adding appwebcam/trunk
Adding appwebcam/trunk/SRC
Adding appwebcam/trunk/bin
Adding appwebcam/logs
Adding appwebcam/branches

To import the created directory structure into the repository, use svn import as shown in line 1 giving the directory you want to import (./appwebcam), the location of the repository (file:///home/user/Repos/appwebcam), and an import comment option (-m “Initial import”) as parameters. This will create an “invisible” directory appwebcam/ under the Repos/ directory.

4. Checking out codes from the repository

[user@mycomp] svn co file:///home/user/Repos/appwebcam/trunk appwebcam
A    appwebcam/SRC
A    appwebcam/bin
Checked out revision 1.

Finally, if you want to checkout a certain portion of your repository, use svn checkout (or svn co). In the above example, only the contents of the trunk/ subdirectory under appwebcam/ are being checkout into the appwebcam/ directory in the user’s current directory. After the checkout, appwebcam/ will contain the SRC/ and bin/ subdirectories.

You may also like...

1 Response

  1. M Beck says:

    Great stuff! Looking forward to read more

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.