Thursday, January 26, 2012

The SVN commands I use the most

In my svn toolbox, I reach for these the most. I hope you find them useful too.

Creating a new branch based on a pre-existing one:

svn copy

Quickly see what files will be merged before actually doing a merge:

cd my_checked_out_repo
svn merge --dry-run -r123:HEAD .

Merging a single commit (the closest thing I can find to a GIT cherry pick):

svn merge -c 123 .

svn merge -c 124 -c 126 .

svn merge -c -r123:126

You can even just grab the part you need within a revision
cd trunk/path/to/file.rb
svn merge -c 123 http://../branches/mybranch/path/to/file.rb file.rb


Say I want to merge my branch into trunk or another branch. I first want to find the revision where my branch actually first became a branch. To do it, use the --stop-on-copy flag.

cd my_checked_out_repo
svn log --stop-on-copy

The result is that I split my branch at revision 123

This gives me a revision number to start from - then:

cd path/to/trunk_or_branch_to_merge_into
svn merge -r123:HEAD .

There may be conflicts. I choose to postpone them so I can do a side by side diff and merge. I use Rubymine for this - but there are other good tools like kdiff3 (excellent tool)

Say you want to move to an entirely new Subversion repository and you want a brand new clean slate - no past revision info - just code:
svn export https://my.subversionhost.com/space_ghost_repo/trunk clean_export
svn co https://my.new_subversionhost.com/new_space_ghost_repo new_project
cp -r clean_export/* new_project/trunk/
cd new_project
svn add *
svn commit -m "First clean slate commit"

No comments:

Post a Comment