Subversion Quick Reference

Having recently switched to doing a lot of development on Ubuntu, I no
longer have the wonderful TortoiseSVN interface to work with, so I’ve
been forced to get familiar with the command line versions. I’ve thrown
together this quick reference guide to help anybody else that feels
daunted by the command line version. It’s really easy, you should learn
it too!

Check out
code from a remote web repository
 
svn checkout http://svn.collab.net/repos/svn/trunk
subversion
OR
svn co http://svn.collab.net/repos/svn/trunk subversion
This command will check out a working copy of the
subversion source code into a new subdirectory called subversion. Note,
this is just an example, checking out the subversion source could take
a while, so don’t do it. You would generally substitute the URL with
the one you are trying to access, and change the working directory to
something different.
svn checkout –username myuser –password …… On the majority of the commands you can set the –username parameter and the –pasword to help automate things, instead of being prompted for them. Once you create a local working copy, your client should really cache that information, however.
     
Basic
Subversion Commands
 
svn update Run this in your project directory to get the latest
changes from the source control server. 
svn update -r 123 Run this in your project directory to update to the
specific revision 123
svn stat
OR
svn st
Run this in your project directory, gives you the
status of all the files and directories. If it returns nothing, then
you are in sync.  M before a file means modified, and ? means
the file is not in source control.
svn revert This will revert the changes that you have made to your
working copy.
svn diff filename.cpp This will show the differences between filename.cpp and
the working copy. This is most useful after running an svn stat and
seeing that the file is modified. You can then run this command to see
what the differences are.
svn revert filename.cpp This will revert all changes you have made to
filename.cpp back to the copy in the repository.
svn revert -R * This will revert all changes you have made to the
entire project back to the repository version.
svn -v list This will list the files in source control for the
current workspace directory
svn -v list http://svn.collab.net/repos/svn/trunk This will list all files in source control at the
particular subversion repository URL. Fairly useful if you want to see
what the structure is before doing a checkout.
svn info Gives you info about the current working copy,
including the URL of the repository it points to, and the last changed
date/author.
svn commit -m “Adding new function” filename.cpp Commit the changes in filename.cpp, and give it a
useful message. Using the messages is highly important down the road
when you want to figure out what a particular change did. Make sure you
use them.
svn commit -m “Adding lots of new functions” Use this function without the filename to commit all
changes to all files. This is useful when you have a set of changes
spanning multiple files. (common)
svn log
svn log filename.cpp
svn log –limit 5 http://svn.collab.net/repos/svn/trunk
Use this function to take a look at the log messages.
The first one is for the entire working copy, the last one shows just
the last 5 log messages on a web repository.
svn add newfile.cpp Add a file or directory to version control. Note that
you still have to commit to actually send the file to the source
control server. You also can only use this command from within a
working copy directory, meaning if you haven’t used source control on
that directory you will need to import it first.
svn move filename.cpp newfilename.cpp Allows you to rename or move files within source
control. You can either use filenames in your local repository, or you
can even pass in two URL locations to have it be moved/renamed on the
server side.
This command is the same as doing a copy and then a delete.
svn copy MySource MyNewSource Allows you to copy a file or directory, either with
local files, or on the repository using the URL syntax.
svn delete filename.cpp Deletes the filename from source control. Note that the
filename will still exist in older revisions, but will be deleted from
the current revision.
svn blame filename.cpp This is one of my favorite commands in subversion. This
lists out the file, giving the revision and person who changed every
single line in the file. Very useful
Import
Code into Subversion
   
svn import -m “Importing the files” MySource

http://svn.theserver.net/svnroot/mysource

Imports the directory MySource and all files contained
within into the subversion server. The URL can be several levels deep
or more.

Note: once you import a source code directory, you should remove the
directory and then checkout the directory so that you can have a proper
working copy. Oh, and back up your files before you delete them. I
don’t want any nasty emails about how you lost source code.

   
For
Administrators
 
svnadmin create /svnroot/RepositoryName Creates a new repository at RepositoryName. If you are
using the URL model for accessing your site, make sure that the
location you create it at is accessible via your local web server.
svnadmin hotcopy /svnroot/reponame /backups/reponame Makes a “Hot Copy” of the repository, which means a
copy of the repository that can be instantly reusable. This method
seems to work pretty well for full backups.
svn copy -m “Making a new branch for that new feature”

http://svn.server.com/svnroot/trunk

http://svn.server.com/branches/johnnysbranch

Make a branch copy of the trunk into a seperate branch.
This should only be used by power users or people that know what they
are doing.
svn copy -m “Tagging version 1.0″ http://svn.server.com/svnroot/trunk
\

http://svn.server.com/svnroot/versions/version_1.0

Tag a version of the application. This uses the same
copy command that the branching does, and it’s really the same
underlying operation. Copying in subversion does not actually make a
new copy of the file, it just tags the current version. Once changes
are made, then the changes would be stored to the file seperately.

6 Responses to “Subversion Quick Reference”

  1. Avinash Says:

    Thanks a million for this quick reference. It has completely weaned me from graphical interfaces like KDESVN. Just love it.
    Also thanks for the ubuntu qref too. (Just as FYI I use kubuntu.)
    I’d been using them for about 8 months.

  2. wieczo Says:

    Nice! Thank you. It helped me getting started.

    There’s an typo: you have to use “–username” and “–password” instead of “-username”.

    Regards!

  3. Dilan Says:

    Great tutorial!! Thanks a lot. It would be wonderful if you can add branching and other parts too..

  4. Antony Jones Says:

    To branch, use ‘svn copy’, and specify the dir to branch into, and the place you’re branching from, i.e:

    svn copy svn+ssh://x/trunk svn+ssh://x/branches/mybranch

  5. Glenn Gentzke Says:

    You might also want to include the Ignore property syntax. I find it to be very useful to clean cruft from your svn stat calls.

    svn propset svn:ignore -F [some_file]
    svn propedit svn:ignore [some_dir]

    The first sets ignore on that one file, the latter opens the ignore property list and allows you to add files and directories to be ignored.

    Especially useful when you use multiple editors that keep a footprint file in your project dir but you dont want it to show up in st or be in the repo.

  6. Dinesh Says:

    how can we use the hot copy….
    like i’m able to create the hot copy but i’m not able to see the contents of it