Monday, October 16, 2006

Subversion Quick Reference

Subversion Quick reference

Check out code from a remote web repository

svn checkout subversion

svn co 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
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 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

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

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.

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

mports 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”

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″

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.