[ # ] Advanced CVS and SVN Tips and Tricks
/* Posted April 28th, 2008 at 3:29pm *//* Filed under Programming, Reference */

I’m listing a few tips and tricks for CVS and SVN that I’ve learned through the years. You’re required to at least have some basic knowledge, this list isn’t a basic usage guide. It’s not a list of basic tips either. These are specifically purposed advanced usage scenarios and the appropriate commands to execute to achieve them. Now that you’ve been informed, let’s start.
Tip #1: How do I to find what are the CVS commits between 2 different dates on a branch?
cvs log -SN -d "2005/8/15<2005/10/27" -r:HEAD
Where August 8, 2005 and October 27, 2005 are the two date ranges you want to specify and “HEAD” is the branch name.
Tip #2: I accidentally checked in a binary file as a text file, how do I fix it?
cvs admin -kb my_binary_file.bin
Remember that the “-kb” is the very same flag you should have specified (but did not do) when you did the first add of the binary file to the repository. This beats removing the file from the repository and adding it again with the binary option.
Tip #3: I checked in a revision for a file that I want to take back, how do I delete it permanently from the CVS repository?
cvs admin -o 1.5 my_file.cpp
Note that you should substitute “1.5″ with the revision you want to remove. After executing this command, the file gets deleted from your checkout so you’ll need to execute an update to bring back the previous revision. That way, you won’t have any issues the next time you work with this file. Be very careful when you use this as you may break existing tags and branches. For example, you may have had revision 1.5 tagged but it now no longer exists in the repository.
Tip #4: How do I ignore whitespace in an SVN diff?
svn diff --diff-cmd diff -x -b myfile.cpp
Where in “–diff-cmd <cmd>” we are specifying the Unix “diff” as the diff tool <cmd> and with “-x <arg>” we are specifying the arguments to pass to the “diff” command. The default would be “-u” but in our case we want to ignore whitespace as well so we use “-b.”
Tip #5: How do specify a date in an SVN diff?
svn diff -r"{2006-07-14}:{2006-07-21}" myfile.cpp
This performs a diff on myfile.cpp between July 14, 2006 and July 21, 2006. While this may not seem like an advanced use case, when specifying dates in SVN it is actually not properly documented that the double quotes are necessary, not in svn help diff nor the official manual. To just update using a date, again use the double quotes:
svn update -r"{2006-08-01}" myfile.cpp
Tip #6: How do I link to an external SVN repository in my SVN repository?
svn propset svn:externals "link_name http://coderetard.com/svn/trunk/link_dir" .
Treat external links as symbolic links, if the linked contents are updated, they will be updated in your repository. Note that the opposite is also true, so consider linking to the external repository’s tag if you do not wish for the contents to change. To specify more than one link, type the [link_name] [link_dir_url] combos for each link on separate lines into a file, then use:
svn propset svn:externals -F my_link_file.txt .
The . at the end of the command is important as it specifies which directory’s svn:externals property should be modified (in this case, the present working directory). To find out what directories are linked, use:
svn proplist --verbose .
Hope this helped you out with your overall CVS/SVN experience. Even if you’ve never had these kinds of issues before, you should bookmark this post in case you ever encounter them in the future. CVS and SVN are both excellent free configuration management tools that will definitely help your software development process. I’ve used some fancy and expensive tools in the past, but CVS and SVN both stack up very well against them, especially when used with the excellent free GUI frontends out there like TortoiseSVN, WinCVS, and TkCVS.













Leave a Reply