SVN and CVS commands
It's no secret that Subversion was developed to replace CVS, and it's for
this reason that both applications are so similar to use. For the client,
many of the commands are identical, and you can often get away with
replacing cvs with svn on the command line. It's the background processing,
the server and the network protocols that are different, and that's largly
transparent to the typical user. Here is a list of some of the commands that
are slightly different:
cvs admin svnadmin Access the administrative front end
cvs annotate svn blame Show revision information for files
cvs co -j svn merge Merge two sources into a working copy
cvs history svn log Outputs the log messages
cvs init svnadmin create Create a new repository
cvs rdiff svn diff Generate list of differences for making a patch
cvs remove svn delete Removes an entry from the repository
cvs rtag svn copy Copies an item including its revision history
Subversion online help
The best way of getting to grips with Subversion is through its excellent
online documentation. Rather than relying on the traditional man of help
commands, svn provides an excellent overview of all its internal commands by
executing svn help from the command line. This provides a list of svn's
internal commands which can themselves be queried by adding them to the end
of the help command:
There is also an excellent online book entitled 'Version Control with
Subversion' that can be either browsed online, or downloaded as a PDF or
HTML document: http://svnbook.red-bean.com/
documented on: 2007-09-22
Subversion usage examples
The following sections teach you how to use different commands in Subversion.
Create a new Subversion archive
To create a new Subversion archive, type the following:
$ cd ~/your-project # go to your source directory
$ svn import http://localhost/repos your-project \
project-name -m "initial project import"
This creates a directory named project-name in your Subversion repository
which contains your project files. Look at http://localhost/repos/ to see if
it's there.
Working with Subversion
Working with project-y using Subversion:
$ cd # move to the work area
$ svn co http://localhost/repos/project-y # Check out sources
$ cd project-y
... do some work ...
$ svn diff # similar to diff -u repository/ local/
$ svn revert modified_file # undo changes to a file
$ svn ci -m "Describe changes" # check in your changes to the repository
$ vi newfile_added
$ svn add newfile_added
$ svn add new_dir # recursively add all files in new_dir
$ svn add -N new_dir2 # nonrecursively add the directory
$ svn ci -m "Added newfile_added, new_dir, new_dir2"
$ svn up # merge in latest version from repository
$ svn log # shows all changes committed
$ svn copy http://localhost/repos/project-y \
http://localhost/repos/project-y-branch \
-m "creating my branch of project-y" # branching project-y
$ svn copy http://localhost/repos/project-y \
http://localhost/repos/proj-y_release1.0 \
-m "project-y 1.0 release" # added release tag
... note that branching and tagging are the same. The only difference
... is that branches get committed whereas tags do not.
... make changes to branch ...
$ # merge branched copy back to main copy
$ svn merge http://localhost/repos/project-y \
http://localhost/repos/project-y-branch
$ svn co -r 4 http://localhost/repos/project-y # get revision 4
Debian Reference
CVS, Sun Jan 14 18:30:35 UTC 2007
Osamu Aoki
documented on: 2007-09-21
April 17th, 2007 mysurface
prefix
The aim of this tutorial is to guide beginners for using svn command line
with simple examples.
This post is not going to focus on svn installation, as the installation is
available anywhere, let me list some links for you in case you are actually
looking for installation.
Subversion Installation References
Installing Subversion (svn) on Linux (Debian Stable)
Setting up Subversion and websvn on Debian
How To Configure Web Access To Subversion Repositories Using Apache
Install SVN with Web Access on Ubuntu
Part 1
How to get help with svn?
If you are looking for svn reference in man pages, you have gone to the
wrong place. To check the references of svn commands, simple do this:
This will make svn list all the available functions, to get the function
reference, let say checkout
The same thing goes to other svn related commands, such as svnadmin
How to create a svn repository?
First of all what is repository? It is a core file for svn, or you can call
it a centralized svn backup database. After created it, it is just a
directory with its files. IMPORTANT! Do NOT try to modify or add something
into the repository, unless you know what are you doing.
To create a svn repo, let say I wanna create a repo to store all my
programming codes, I do this
svnadmin create /home/mysurface/repo/programming_repo
Remember try to use absolute path for everything, sometimes the relative
path is not going to work.
How to import my existing directories into the new repo?
svn import /home/mysurface/programming file:///home/mysurface/repo/programming_repo -m "Initial import"
-m stand for log message, the first revision was created with log as
"Initial import". You need to specified URL for the repo, URL is the
standard argument for svn. Therefore for local file, you need to specified
with file://
How to see what is inside the repo?
svn list file:///home/mysurface/repo/programming_repo
Another way of listing all the files and folder in the tree view, I use svnlook
svnlook tree programming_repo
The difference between svn list and svnlook tree is one expect URL another
one do not.
Part 2
Part 2 will covers how to checkout, track changes, commit, add or delete
files and message logs.
How to checkout files from svn repo?
This is the most critical part of svn and also the most common part of svn
command line. A lots of open source development projects provided the way
for user to check out their latest code through the internet.
You need to check out in order to commit the changes to svn repo
later. Refers back to the previous post, where I import entire directory
/home/mysurface/programming to programming_repo. I am going to checkout to
the same folder. If you are skeptical of doing this, you may want to backup
the directory first.
mv programming programming-bk
Now checkout to programming, mkdir is not needed, as svn will create the
directory for you if it is doesn't exist.
svn co file:///home/mysurface/repo/programming_repo programming
co is the shortform of checkout.
Okay, lets just compare both folder with diff and store the result into a
file comp.diff
diff programming programming-bk > comp.diff
Diff will list the folder in common, and also the differences. Check
comp.diff, as it tracks the additional folder .svn that only exist in
programming/. Again, do NOT modified or delete this folder.
Are you convinced to remove your programming-bk/ ? Make sure you keep the
repo safe and you can check out the same data anytime, at any place.
You can even checkout only a specific folder from your repo. e.g.
svn co file:///home/mysurface/repo/programming_repo/c/curses
This will only check out a folder at current directory.
Single file can't be checkout like directories, but you can extract them
from repository by svn export
svn export file:///home/mysurface/repo/programming_repo/c/curses/matrix.cc
How to track the changes before commit to repo?
First of all, you track what files had changed,
It will list files which have changed, with some attributes besides the
filename. Common attributes are M, ?, A … M is modified, A is newly added
(how to add refers later section), ? indicate the file is added into local
directory but not added into repo.
Secondly, you want to track the differences between the previous revision
and the working one. Lets assume color.c has changed,
I name it as svndiff and place it at /usr/bin, change the mode to executable.
chmod +x /usr/bin/svndiff
Now, I can simply do this,
To close the vimdiff, type :qa
How to commit the changes?
You can commit with -m to place your log message if it is short. But if it
is long, I suggest you to make use of your default editor. I am a vim user,
therefore I add a line into my ~/.bashrc
Now I can commit with this:
ci is the shortform of checkin as in "check in", or commit. Write the log
message and close save vim :x , I am done. The same way as checkout, you can
choose to commit one file or any folder.
How to add or delete file to or from repo?
The file won't be committed if you don't add it into repo. Therefore you
need to add it manually if you want it to goes into your repo. Let say you
wanna add a new file color2.cc
Delete does the same way, if you only delete file at your working directory,
it won't reflects the changes to our repo.
How to check the logs for each revision?
The simplest way is doing just,
It will list all logs, start from latest revision. That is really
irritating! You can limit it to 3 latest revision log by doing this
If you wanna check for specific revision, specified with -r,
I find something awkward, let say I have done svn delete at revision 3
(latest), and revision 2 is the changes of the deleted file at revision
3. When I do svn log, by right it should show all 3 logs, but It only shows
for revision 1. It means the svn log will only shows the log if the file is
exist, bear in mind.
How to update the working directory into the latest revision?
Update to specific revision?
*Tags*: svn tutorial, subversion, svn howto, source version control
documented on: 2007-09-21
Edited by xpt on 2007-09-21.
Subversion is a file revision control system for developers.
Create a new repository
Repository is the place where the versioned data lives in a database. Go to
the computer where the repository lives. Be the user who is repsonsible for
the repository.
$ svnadmin create /data/subversion
Initial import
Import to a local repository
develop$ svn import findus4 file:///data/subversion/findus4
Import to a webdav-repository
develop$ svn import findus4 http://svn.rosi13.de/svn/findus4
Creating a trunk-directory, initial import, checkout:
develop$ svn mkdir http://svn.rosi13.de/svn/findus4/trunk
develop$ cd findus4
develop$ svn import -m "initial import" http://svn.rosi13.de/svn/findus4/trunk
develop$ mv findus4 findus4.old
develop$ mkdir findus4
develop$ svn checkout http://svn.rosi13.de/svn/findus4/trunk findus4
develop$ rm rf findus4.old
Other things
Checkout
Checkout, getting out files from repository
svn checkout file:///data/subversion/findus4
svn checkout http://subversion.rosi13.de/subversion/test
Checkout behind the proxy-server
Checkout, getting out files from repository when you are *behind a
proxy-server*
So, you are behind a proxyserver and want to access the repository through this proxyserver.
svn commit
Putting changed file to repository
You don't need the place of the repository anymore, svn remembers it.
svn status
Which files have changed? Are there new files?
svn diff
svn add
svn add MyNewFile.pm (schedules file to next update)
svn commit (puts diffs and this new file to repos)
svn:ignore
Ignore files in a directory
-
Before this do an 'svn commit'
-
Do
svn propedit svn:ignore .
-
Every file to be ignored in a new line
-
Do
svn commit -m "ignoring this and that"
split repository
Moving projects from a common used repository to several single repositories
-
Dump complete subversion-repository to a file:
$ svnadmin dump /data/subversion >complete.svn.dump
Create an extract from your first project:
$ cat complete.svn.dump | svndumpfilter \
--drop-empty-revs \
--renumber-revs \
include project007 \
>project007.svn.dump
-
Create new repository:
$ svnadmin create /data/subversion/project007
-
Import complete history to new repository
$svnadmin load /data/subversion/project007 <project007.svn.dump
svn:keywords
Activate creating keywords
svn propset svn:keywords "Revision Date Id HeadURL Author" myfile.pm
Sending Mails when commiting files
Install these package in debian-linux on your subversion-server:
libsvn-notify-perl - Subversion activity notification.
% apt-get install libsvn-notify-perl
% svnnotify
Missing required "--repos-path" parameter
If you get this error-message then you are ready to run this script when
commiting code. To do this write a command into the shell-script
post-commit, which is already there in your repository-directory:
cd /data/svn/findus/hooks/
ls -l
#!/bin/sh
svnnotify --repos-path "$1" --revision "$2" \
--to one@dontcare.com,two@dontcare.com \
--reply-to responsible-for-everything@somewhere.com \
--language de
You get a mail like this after commit code:
Revision: 329
Author: horshack
Date: 2006-01-31 22:27:05 +0100 (Tue, 31 Jan 2006)
Log Message:
-----------
this is the commit-message bla bla
Modified Paths:
--------------
trunk/findus_mini.ini
Restrict ssh-login to subversion only
Your ~/.ssh/authorized_keys file has to look like this (everything must be
in a single line):
command="/usr/bin/svnserve --tunnel --root=/var/svn",no-port-forwarding,no-agent-forwarding,no-X11-forwarding,no-pty ssh-dss AAAAB3N...
This makes that whatever program the user tries to run via ssh, he will
always run
/usr/bin/svnserver --tunnel...
The user can only access svn-repositories in /var/svn.
When you have a repository /data/svn/findus/trunk he has to do this:
svn checkout svn+ssh://username@svn.juhei.org/data/svn/findus/trunk findus
Books
documented on: 2007-09-21