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

   1: [user@mycomp] cd
   2: [user@mycomp] mkdir Repos
   3: [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

   1: [user@mycomp] mkdir appwebcam
   2: [user@mycomp] mkdir appwebcam/trunk
   3: [user@mycomp] mkdir appwebcam/logs
   4: [user@mycomp] mkdir appwebcam/branches
   5: [user@mycomp] mkdir appwebcam/trunk/SRC
   6: [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

   1: [user@mycomp] svn import ./appwebcam file:///home/user/Repos/appwebcam -m "Initial import"
   2: Adding appwebcam/trunk
   3: Adding appwebcam/trunk/SRC
   4: Adding appwebcam/trunk/bin
   5: Adding appwebcam/logs
   6: 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

   1: [user@mycomp] svn co file:///home/user/Repos/appwebcam/trunk appwebcam
   2: A    appwebcam/SRC
   3: A    appwebcam/bin
   4: 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.

One Response to All about SVN

  1. M Beck says:

    Great stuff! Looking forward to read more

Leave a Reply