To make a long story short, we all know how CVS works ... more or less. The easiest way to understand the basic difference between the two is CVS works with files and SVN works with the entire tree. So each time ANYTHING (file, directory, link) is committed, SVN takes a snapshot of the entire tree and increments the revision number. Need more info? The easy to read manual for SVN can be found here or from their website, http://svnbook.red-bean.com.
It is possible to access the SVN repository locally on smote.cs, but SVN also allows users to work with a remote repository. There are several methods SVN can use to access a remote repository, but we have elected to use the svn+ssh method allowing us to use our EECS accounts.To be able to access the repository on smote.cs remotely, you will need to create a new ssh key for this purpose. To create a new key for SVN, issue the following command:
% ssh-keygen -t dsaAppend the public file (.pub) to the file named authorized_keys. In this example, the public file would be called id_dsa.subverion.pub. Next, edit the authorized_keys file.
Generating public/private dsa key pair.
Enter file in which to save the key (/home/cs/myacct/.ssh/id_dsa): /home/cs/myacct/.ssh/id_dsa.subversion
You can enter any filename, but you should not accept the default choice since it will overwrite your current id_dsa file.
Finally, add this environment variable to your profile.
Look for the new entry starting with ssh-dss AAAA ....
Prepend the following to the entry including the quotes:
command="/usr/bin/svnserve -t -r /project/eecs/tinyos/www/smote.cs.berkeley.edu/SVN"
The -t is for tunneling through SSH and the -r helps SVN determine the root of the repository.
The line should like similar to the line below:
command="/usr/bin/svnserve -t -r /project/eecs/tinyos/www/smote.cs.berkeley.edu/SVN" ssh-dss AAAA ....export SVN_SSH="ssh -i $HOME/.ssh/id_dsa.subversion"
This references the newly created private key.
NOTE: If you created your keys on a Debian-based PC during the time when a vulnerability was discovered, you will need to re-create your keys. Thank you, Steve and Arsalan, for figuring this out!
Note for Non-EECS PCs
If you would like to access the repository from a non-EECS linux-based PC, copy your id_dsa.subversion file from your EECS account to your local .ssh directory and make sure the SVN_SSH environment variable is assigned. The only difference in issuing a command is the need to add the EECS account name as a prefix. For example,
% svn list svn+ssh://myacct@smote/Thank you Jay for asking about this procedure.
Commands in SVN are very similar to the ones found in CVS. Listed here are the most common commands in SVN. Detailed explanations of these commands can be found in the manual or at the SVN website. Many commands assume you are in the working directory. If a command doesn't seem to work, make sure you are in the appropriate directory or specify the path to the directory.
% svn import myproject svn+ssh://smote/myproject -m "Initial"
This copies the local directory myproject to the repository into a direcotory called myproject.
Leaving off the directory name on the repository's arg will store all the files in the repository's
root directory. The -m option gives the version a description. In this case, "Initial."
% svn -v list svn+ssh://smote/myproject
List the files that were uploaded to myproject in the repository.
The -v option requests a verbose output.
% mv myproject myproject.orig
Just as in CVS, the files must be checked out.
In preparation, store the original copy or cd to your new workspace.
% svn checkout svn+ssh://smote/myproject
Besides copying the directory myproject and its contents to your workspace, SVN will
setup the .svn subdirectory. The abbreviation 'co' can be used in place of the keyword 'checkout'.
% ... do some work ....
% svn status path/to/myproject
This command will only return the names of the files that have been modifed locally.
Leaving off the directory/path name will only check the files in the current directory.
% svn -v status path/to/myproject
This command will display the status and revision numbers of all the files in the directory.
Leaving off the directory/path name will only check the files in the current directory.
% svn update path/to/myproject
Prior to a commit and during editing, it is advised to issue an update to make sure your local
copy is up to date. Leaving off the directory/path name will only check the files in the
current directory.
% svn commit path/to/myproject -m "fixed broken code"
Commit the changes to the repository. Leaving off the directory name will only check the files
in from the current directory.
If you receive a "out-of-date" error, issue a 'svn update' to merge your working copy
with the most current copy in the repository. If you haven't updated recently, there
may be conflicts forcing you to perform the update manually.
Many of the remaining examples on this page were borrowed from the manual, but have been compiled into a short little list here. Again, further detail about the operation of SVN can be found in the manual.% svn add file_or_dir
Mark a file, directory, or symlink to be added to the repository.
The marked item will not be added to the repository until a 'svn commit' is issued.
% svn delete file_or_dir
Mark a file, directory, or symlink to be deleted from the repository.
The marked item will not be deleted from the repository until a 'svn commit' is issued.
% svn copy foo bar
Create a copy and mark it.
The marked item will not be copied to the repository until a 'svn commit' is issued.
% svn move foo bar
Move a file, directory, synlink. Similar to a svn copy follwed by a svn delete.
The marked item will not be "moved" within the repository until a 'svn commit' is issued.
% svn mkdir foo
Create a directory and mark it.
The marked item will not be created in the repository until a 'svn commit' is issued.
% svn add foo
% svn delete bar
% svn revert foo bar
Revert is basically an undo provided a 'svn commit' has not been issued.
In this example, foo will not be added and bar will not be deleted.
% svn commit
All of the commands above need a 'svn commit' issued to make changes to the repository.
Many commands will accept the -r or --revision option allowing you to specify a particular revision or range of revisions. r1 and r2 can be any combination of revision number, keyword, or date.-r Keywords
HEAD - Youngest revision in repository.
BASE - Revision number of the local copy prior to any local modifications.
COMMITTED - Most recent revision prior to or equal to BASE.
PREV - Revision immediately before the last revision (COMMITTED - 1).
% svn diff -r PREV:COMMITTED foo.nc
Display the last change committed to foo.nc
% svn log -r HEAD
Display the log messages for the latest repository commit
% svn diff -r HEAD
Compares the working copy against the latest version in the repository.
% svn diff -r BASE:HEAD foo.nc
Compares the unmodified version of foo.nc with the latest version of foo.nc in the repository.
% svn log -r BASE:HEAD
Display all the commit logs since the last update.
% svn update -r PREV foo.nc
Rewinds the last change on foo.nc. This also decrements foo.nc's working revision number.
% svn diff -r BASE:14 foo.nc
Compare the unmodified version of foo.nc with the way it looked in revision 14.
Using dates with -rRevision dates follow the ISO-8601 date and time formats along with a few other formats.% svn checkout -r {2006-02-17}
% svn checkout -r {15:30}
% svn checkout -r {15:30:00.200000}
% svn checkout -r {"20076-02-17 15:30"}
% svn log -r {2006-11-28}
% svn log -r {2006-11-20}:{2006-11-29}
If no time is specified, SVN will assume 00:00:00. Therefore, if you wanted to checkout a version committed sometime during the day on 2008-02-14, you will need to specify 2008-02-15.
More -r examples% svn cat -r 2 foo.nc >foo.nc.r2
% svn cat -r 2 svn+ssh://smote/myproject/foo.nc >foo.nc.r2
cat the contents of revision 2 of foo.nc and redirect it to a file.
% svn checkout -r 12 svn+ssh://smote/myproject
Retrieve the 12th revision of myproject.
% svn update -r 12 svn+ssh://smote/myproject
Update your working copy to the 12th revision of myproject.
svn diff
% svn diff
Compare the working copy with the cached pristine copy
% svn diff -r 3 main.nc
Compare the working copy with revision 3 in the repository.
% svn diff -r 2:3
Compare revision 2 and 3.
% svn diff -c 4 main.nc
The -c option instructs diff to compare the revision specified on the command line
with the previous version. This will compare revision 4 with revision 3.
% svn diff -c 5 svn+ssh://smote/myproject/main.nc
Compares revision 5 with revision 4 from the repository.
svn log
% svn log foo.nc
% svn log svn+ssh://smote/foo.nc
Display the log for foo.nc.
% svn log -r 5:19
Display logs for revision 5 through revision 19.
% svn log -r 19:5
Display logs for revision 5 through revision 19 in reverse order.
% svn log -q -v
-q (quite) and -v (verbose) in combination will display the filenames of files that have changed.
$ svn updateIf you try to do an update and the status of one of the files is a 'C', there is a conflict between the current version in the repository and your working version. If there is a conflict, it means SVN could not merge the two versions, and requires you to manually resolve the problems.
C foo.nc
Updated to revision 46.
If there is a conflict, three files will be created.
filename.mine - Your working copy before updating.You now have three choices on how to proceed.
filename.rOLDREV - How the file looked when it was checked out.
filename.rNEWREV - The current version of the file from the repository.
Once everything is resolved, you must issue a svn resolved filename which will remove the three temporary files and reset the status of the file. If you are satisfied with your changes, issue a svn commit.
- You can merge the files by hand.
- Copy one of the temporary files on to your working copy.
- Issue a 'svn revert filename' to throw away all of your local changes.
If you experience a crash during a commit, there is a possibility of recovering your changes by issuing a svn cleanup. svn cleanup goes through any leftover logs trying to recover your work.
Locks are available for serialization, but can easily be by-passed.% svn lock foo.nc -m "editing file for release"
Create a lock.
% svn info foo.nc
Display infomation about foo.nc including any locks that may exist.
% svn unlock foo.nc
To remove a lock, either commit the file or unlock it.
% svn unlock --force foo.nc
To forcibly unlock a file, add the option --force.
% svn lock --force foo.nc
To forcibly steal a lock, add the option --force.
Create a branch by copying.% svn checkout http://smote/myprojectMerging a branch
% cd myproject
% ls
trunk/ branches/
% svn copy trunk branches/mycopy
% svn commit -m "creating a private branch"
or
% svn copy http://smote/myproject/trunk http://smote/myproject/branches/mycopy -m "creating a private branch"
% svn diff -c 344 http://smote/myproject/trunk
Determine the changes from revision 343 and 344 in the main trunk.
% svn merge -c 344 http://smote/myproject/trunk
Merge those changes into your branch copy.
% svn commit -m "merged 344 into local"
Create a local copy without the all the .svn directories.
% svn export http://smote/myproj -r 1729