Subversion Quick Reference
Wednesday, December 27, 2006
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!
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 |
| 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. |
April 5th, 2007 at 1:54 am
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.
August 14th, 2007 at 1:29 pm
Nice! Thank you. It helped me getting started.
There’s an typo: you have to use “–username” and “–password” instead of “-username”.
Regards!
October 24th, 2007 at 12:25 am
Great tutorial!! Thanks a lot. It would be wonderful if you can add branching and other parts too..
October 25th, 2007 at 1:17 am
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
February 15th, 2008 at 10:10 am
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.
April 3rd, 2008 at 8:39 pm
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
April 9th, 2008 at 11:51 am
Good little guide. Would be gooder with a branching quick quide. :-)
July 17th, 2008 at 2:23 pm
Tank you sir. Have you though to extend it a little bit more?
August 28th, 2008 at 9:38 am
Very good list. Thanks.
Any idea, how to reject commits (for admins) in case the repository is closed for commits for temporary reasons.
September 24th, 2008 at 1:28 am
thanks for list, could you add to your list: admin export, and admin sw commands ..
December 4th, 2008 at 10:35 pm
Well, thank you very much! You really did a good job! Thank you!
December 4th, 2008 at 10:39 pm
I think it is great! Thanks for your information.
December 18th, 2008 at 1:25 am
Thanks for sharing!
December 25th, 2008 at 8:12 pm
Great!
December 29th, 2008 at 1:09 am
Very very nice. One thing I noticed with the explosion of web 2.0, there are so many javascript/ajax libraries. It is always good to have choices but gets little confusing. Do you use anything other than mentioned above? I would love to see a guide that explains what libraries do you use and when.You can go to http://www.gizmograbber.com/article/cheap-car-stereo.html
to know something about Cheap car stereo.
December 30th, 2008 at 6:33 pm
For those of you that are unfamiliar, Firebug is an extension for Firefox that lets you do real debugging of javascript. It’s an excellent tool that doesn’t have a match anywhere in terms of ease of use and power.Karaoke player http://www.ace-karaoke.net/karaoke-player.htm
Chinese karaoke songs http://www.ace-karaoke.net/karaoke-songs/chinese-karaoke-songs.htm
March 26th, 2009 at 1:48 am
After I read your post, I find I learn a lot, thanks, buddy! :)
http://www.sealtapes.com/sitemaps/Tamper-evident-tape.html
June 7th, 2009 at 10:14 am
thanks for this great guide.. wish you could be more details