Tuesday, August 17, 2010

Begin with svn

Hi, i am a beginner myself and i found it very hard get any information about svn to begin with. Later i found that svn is so simple that most of the time spend on gathering information was a waste, hence this blog. (This blog assumes that you are working in LINUX environment)


About svn: svn is  a revision control system. What it means is that it provides an environment where one can maintain current and historical versions of his files such as source codes, web pages, documentation etc. It is used usually in medium to big project where the product has to go through various stages. It also provides a neat way for many different programmers to collaborate and make changes to the project at the same time. The programmer can any time go to any of the previous version of his project and start making changes from there. In fact svn is the most professional way for project on which multiple people are working. You can also use it for you own codes especially if you are making a small software kind of thing where you often encounter bugs etc and want to revert back to previous version.

 First time task (for admin):
  • Check if svn is installed.  To check this, type


    svn help
    in terminal and wait for response. If it is not installed, then you can find install instructions from here.
  • Decide on choosing a central server on which all files will be kept. If you want to use svn for personal usage only, you can choose your own computer, otherwise you need to choose a place accessible to all the people working on your project. You can have it either on LAN or on internet. To have it hosted on internet, you need to choose a repository sever. Many websites offer this facility. I used googlecode for my project. 
  • If you are creating svn repository on you local workspace you need to first choose a directory. Once done, the syntax to create an svn repository is:

    svnadmin create <repo direcotory>
  •  This is the central repo where all users will access the files and edit them. Never make any changes directly to the repo directory unless you know what you are doing. Henceforth i will refer to the repo location as $REPO. Remember that $REPO is a url, so even if it is on the same computer, better use 'file:///home/mysurface/repo/programming_repo' than the local path as $REPO
  • Also the svn directory needs to begin with some content unless everything is added from scratch. To initialize svn , execute the following:
svn import $BASEDIR $REPO -m "Initial import"
where $BASEDIR is the folder from where the content is to be uploaded.
     First time task (for each member)
    • Create a local working directory which will store a copy of the local version of the data base. Assuming this directory has been created and it is $WDIR, use the command

      svn co $REPO $WDIR
      . This command will download and make local copy of the repository.
    Regular commands on svn
    • Whenever you start working on the project, first go to $WDIR and execute:

      svn update
      . This will update your local copy to the latest copy in case someone else has commited some changes in the meanwhile. This command can also be used to rollback to one of the previous versions.

      svn update -r $n
      where $n is the version number that you want to recover. After executing this, your directory will have contents of exactly the $n th version.
    • When done working, you need to write your changes to the central repository(commit). Command:

      svn ci -m "log message about the current update"
      Where the message enclosed in quotes is in fact the log message. Log message is a message that you pass everytime you make update to the directory. It is mainly to describe the changes you have made for others(and yourself) to read.
    • When making changes, if you want to know all the changes you have made since last commit, you can do so using the command

      svn status
    • To view the contents of an svn repo, use

      svn list $REPO
    • To view the changes made to a particular file, use

      svn diff $FILE
    •  When you add a file to your working directory, it is not added by default to your local svn repository. Hence, you need to execute 
    • svn add $FILE
      so that it gets added to you local svn.
    • To delete, use 
    • svn delete $FILE    
    • To view log messages, use
      • svn log 
        to view log messages of last $n versions, use
        svn log --limit $n 
        to view log message of nth version use:
         svn log -r $n 
    • Help: 
    svn help