Monday, October 24, 2011

How to create a SVN repository

This is from my Advanced programming class notes:


Subversion (svn) is a source code version management system.  Such a
system is most useful when you work in a team, but even when you’re
working alone, it’s a very useful tool to keep track of the changes
you have made to your code.
In this class, the use of a version control system is required.  If
you are already familiar with another system such as Perforce or
BitKeeper, you can talk to me about using them instead of svn.  (But
not cvs.  I want cvs users to switch to svn in this class.) You’ll
learn the basics of svn in this part of the lab assignment.
(a) Creating the Subversion source repository
The first thing you need to do is to create a repository under your
home directory so that svn can store revision histroy of your files.
    $ cd ˜
    $ mkdir svnrepos
    $ chmod 700 svnrepos
    $ svnadmin create ˜/svnrepos
(b) Adding a directory to the repository
This process creates a subdirectory in your svn repository.  We create
a subdirectory called "cs3157" which will house all our code in this
class.
    $ cd ˜
    $ svn mkdir file://$HOME/svnrepos/cs3157
svn will start your editor to ask you to say something about what
you’re doing.  Type "create cs3157 subdirectory" on the 1st line, save
and quit the editor.  You do this everytime you "commit" a change to
the svn repository.
You can list the content of your repository using:
    $ svn list file://$HOME/svnrepos
(c) Checking out cs3157 directory into a local working directory
Note that we created the cs3157 "subdirectory" in the repository, not
in your home directory.  In fact, cs3157 is a subdirectory in the
repository in a logical sense; if you look in ˜/svnrepos, you won’t
find any directory named cs3157.
Now we will create a physical "working copy" of the cs3157
subdirectory by "checking it out".
    $ cd ˜
    $ svn checkout file://$HOME/svnrepos/cs3157Now you can see there is a physical directory cs3157 under your home
directory.  Go into it and see what’s in there.
    $ cd ˜/cs3157
    $ ls -alp
Note that the directory contains a subdirectory called ".svn".
Subversion uses that directory to manage your working directory.  This
directory should be included in your submissions so that we can verify
that you’re using svn correctly.
(d) Creating and adding a directory for this lab session
    $ cd ˜/cs3157
    $ mkdir lab1
    $ svn add lab1
Or in one step,
    $ cd ˜/cs3157
    $ svn mkdir lab1
Your action of adding the lab1 directory to the svn repository is now
pending.  Type "svn status" to see what’s pending.
You "commit" your changes by:
    $ svn commit

(e) Adding files
Let’s add part2 directory first:
    $ cd ˜/cs3157/lab1
    $ svn mkdir part2
    $ cd part2
Now you are ready to write code!  Using your editor, write hello.c and
add it to the respository.
    $ vim hello.c
 
        #include <stdio.h>
        int main() {
            puts("hello world!");
            return 0;
        }
    $ svn add hello.c
Try compiling and running:
    $ gcc -g -Wall -o hello hello.c
    $ ./hello
Finally, commit the change you’ve made.    $ svn commit
(f) Other svn commands
To see the status of your files in the current directory in relation
to the repository:
    $ svn status
To see the difference between your working files and the latest
committed versions in the repository:
    $ svn diff
To print out log information:
    $ svn log hello.c
If you want to abandon the changes you made to your working copy, and
revert the file into the version last commited to svn (losing all your
changes!!!):
    $ svn revert hello.c
You can delete a file with "svn rm" command.  Type:
    $ svn rm hello.c
If you do "ls", you’ll see that your local copy of hello.c is gone.
However, the deletion is still pending, since you did not commit your
action yet.  You can get back your hello.c by typing:
    $ svn revert hello.c
You can see a manual page of any svn command using "svn help".  Try:
    $ svn help
    $ svn help status
Lastly, "svn update" command is normally used for collaboration.  For
example if you were working in a team working on a same set of code,
you would typically issue "svn update" in the beginning of your day to
bring in your teammates’ commited changes.

No comments: