Beginner Linux Tutorials Intermediate Linux Tutorials Advanced Linux Tutorials

Welcome to Our Community

While has been around for a while, we recently changed management and had to purge most of the content (including users). If you signed up before April 23rd please sign up again. Thanks!

Linux and Subversion

Discussion in 'Advanced Tutorials' started by Rob, Jul 10, 2013.

  1. Rob

    Rob Administrator
    Staff Member

    Oct 27, 2011
    Likes Received:
    Subversion is an alternative to CVS that is growing in popularity.

    Installing Subversion

    Users of Debian and Debian-based distributions (like Ubuntu) just need to issue the following command:

    apt-get install subversion subversion-tools
    Subversion packages are also included in Red Hat's Fedora Core distribution. If you have the 'yum' package management system installed, you can install subversion by issuing the command:

    yum install subversion
    There, of course, also exists the possibility of installing from source.

    Creating a Repository

    First, I created a directory called 'dev' in /home/mike where I am going to keep the repositories for projects I work on. Essentially, what happens is that you have a directory where you're working and a directory where the repository stores that work for version control purposes. These are, of course, separate.

    Let's say you've been offered a project to design a website for a restaurant called Larry's Clam Shack. If you want to use subversion for version control on the project, you need to first create a repository. To do this, issue the following command:

    svnadmin create /home/mike/dev/clamshack
    Once created, the directory structure will look like this:

    drwxr-xr-x  2 mike mike 4096 2005-09-14 17:29 conf
    drwxr-xr-x  2 mike mike 4096 2005-09-14 17:29 dav
    drwxr-sr-x  2 mike mike 4096 2005-09-14 17:29 db
    -r--r--r--  1 mike mike    2 2005-09-14 17:29 format
    drwxr-xr-x  2 mike mike 4096 2005-09-14 17:29 hooks
    drwxr-xr-x  2 mike mike 4096 2005-09-14 17:29 locks
    -rw-r--r--  1 mike mike  379 2005-09-14 17:29 README.txt

    According to the developers, it's a good idea to set up your directory structure for optimum use of subversion. First, create a temporary directory (call it 'tmp' if you want) Then create this directory structure inside of 'tmp':

    mkdir larrycs
    mkdir larrycs/trunk
    mkdir larrycs/branches
    mkdir larrycs/tags

    Now what we'll do is import this layout tree into the subversion repository 'dev':

    svn import . file:///home/mike/dev/clamshack --message 'creating clam shack repository'
    You'll see a message like this:

    Adding        larrycs
    Adding        larrycs/trunk
    Adding        larrycs/branches
    Adding        larrycs/tags
    Committed revision 1.

    You can verify that it got created by issuing the command:

    svn list --verbose file:///home/mike/dev/clamshack
    Feel free to remove 'tmp'. I did, anyway, because I get confused easily. I'm actually going to do my work in a directory which will get me the prize for originality: 'work' Now that you're ready to start using the repository. You need to go to the directory that corresponds to 'work' and \"checkout\" the repository. Once you're in your work directory, issue the following command:

    svn checkout file:///home/mike/dev/clamshack
    You should see the following:

    drwxr-xr-x  3 mike mike 4096 2005-09-13 18:51 branches
    drwxr-xr-x  3 mike mike 4096 2005-09-13 18:51 tags
    drwxr-xr-x  4 mike mike 4096 2005-09-13 18:59 trunk

    Working With Subversion

    Now that you've got your work area set up, you are free to add files. If you look inside the directory that the checkout created, you'll find the layout we set up for subversion:

    drwxr-xr-x  3 mike mike 4096 2005-09-13 18:51 branches
    drwxr-xr-x  3 mike mike 4096 2005-09-13 18:51 tags
    drwxr-xr-x  4 mike mike 4096 2005-09-13 18:59 trunk

    It's in the 'trunk' directory where we'll be storing out files. For example, I first created a directory to save the documentation for the project then I added it to the repository:

    svn add docs/
    Then we would commit it to the repository. Doing a 'commit' is like saying: "Yes, I really want this in there".

    svn commit -m "docs dir" docs/
    In the docs/ directory, I created a file called 'notes' where I will jot down things that I have to remember about the project. After creating the first entry, I added it as well:

    svn add notes
    And then I committed it:

    svn commit -m "notes file" notes
    I assume you're getting the idea here.

    You can leave off the -m \"message here\" part and your default text editor will pop up and ask you to write the message there. I prefer to save a step, so I don't do it. If you do have some lengthy message to write, it might be a better idea to leave it off and use the text editor.

    As you're working on your project, and you want to see what changes you've been making, you can issue the following command to see that:

    svn log notes
    If you're hard at work on your work copy and you want to look at the differences between what you've got and what you started with, you can issue a diff command:

    svn diff notes
    If you find that you're changes aren't what you really wanted, you can convert (or revert) back to the repository's copy with:

    svn revert notes
    Advantages to Using Subversion

    Since subversion was meant to be a substitute for CVS, its advantages are essentially fixes of what was lacking in CVS. For example, aborted commit actions in CVS sometimes result in the corruption of the repository. This doesn't happen with subversion. There is also better support for retaining version and history information of files when they are moved or renamed. It has also better built-in binary file support than CVS.

    At any rate, whether you use CVS or subversion, there's no debate about the importance of some version control system for a programmer.

Share This Page