Better Merging with Subversion [www.orcaware.com]


(photo by HubbleSite - NewsCenter)

In an earlier blog post about branching and merging with subversion, I detailed how I do merging with subversion alone. 

It's great to understand the basics but as Mark Aufflick commented on that same article, you're crazy if you don't use "svnmerge.py".

So, what is svnmerge.py? Why do you need it?

The problem stems from the fact that Subversion, older than version 1.5, do not keep track of your merges.

As a result, the developer needs to keep track of merges manually. This means that a developer will have to take note of which revisions were merged to the trunk or to a branch. If the developer is not organized and diligent with tracking his/her merges, it is perfectly possible to "remerge" revisions that have already been merged before, resulting into lots of conflicts and hours of trying to sort them out.

If you're working on a project with just one trunk, one branch, and just one developer, you could probably get by without svnmerge.py but the reality is that most projects have one trunk, multiple branches, and multiple geographically dispersed developers.

Here's the step-by-step guide on merging changes from a branch back to the trunk but this time we'll use svnmerge.py. Note that you will need subversion 1.1 or higher and svnmerge.py r22788 or higher.

  1. As before I followed the recommended layout for a version control project where you have trunk, branches, and tags

    	http://code.solutiongrove.com/svn/viewvc.cgi/monitorex/trunk/
    	http://code.solutiongrove.com/svn/viewvc.cgi/monitorex/branches/
    	http://code.solutiongrove.com/svn/viewvc.cgi/monitorex/tags/
    	
  2. First I need to activate merge tracking on the trunk by checking out a clean copy of the trunk and executing "svnmerge.py init" on it and commit. This is done only once on the trunk. For each new branch created from the trunk you need to repeat step 3 below.
    	mkdir workspace
    	svn checkout svn+ssh://ham@code.solutiongrove.com/home/code/svnrepo/solutiongrove/monitorex/trunk trunk
    	cd  trunk
    	svnmerge.py init
    	svn ci -F svnmerge-commit-message.txt
    	rm svnmerge-commit-message.txt
    	
  3. Next (1) I create the branch, (2) initialize it for merge tracking, and (3) configure the trunk to be aware of merges from that branch. These steps are only done once per branch.

    	cd workspace
    	svn cp svn+ssh://ham@code.solutiongrove.com/home/code/svnrepo/solutiongrove/monitorex/trunk \ 
    	svn+ssh://ham@code.solutiongrove.com/home/code/svnrepo/solutiongrove/monitorex/branches/mytestbranch
    	svn checkout svn+ssh://ham@code.solutiongrove.com/home/code/svnrepo/solutiongrove/monitorex/branches/mytestbranch/ mytestbranch
    	cd mytestbranch
    	svnmerge.py init
    	svn ci -F svnmerge-commit-message.txt
    	rm svnmerge-commit-message.txt
    	svn checkout svn+ssh://ham@code.solutiongrove.com/home/code/svnrepo/solutiongrove/monitorex/trunk trunk
    	cd  ../trunk
    	svnmerge.py init svn+ssh://ham@code.solutiongrove.com/home/code/svnrepo/solutiongrove/monitorex/branches/mytestbranch
    	svn ci -F svnmerge-commit-message.txt
    	rm svnmerge-commit-message.txt
    	
  4. Work on the branch and commit any new stuff to it.
  5. Check what to merge back. I go into the copy of trunk I checked out and see what changes from the branch are available.

    	cd workspace/trunk
    	svnmerge.py avail --bidirectional --log
    	
  6. The avail command will list all available revisions from branches that you can merge back to the trunk. Adding "--bidirectional"  will make svnmerge do some additional processing/checking and will probably be more accurate specially if merges to the branch are being tracked like it is in our case. Adding "--log" will include the commit messages for each revision, this makes it easier to recall what changse are associated with the revision number.
  7. I choose the revisions I want to merge back and use the svnmerge.py merge command. Let's say for instance, that I want to merge back a fictitious revision r2345 committed in the branch back to trunk

    	cd workspace/trunk
    	svnmerge.py merge --bidirectional -r2345
    	svn ci -F svnmerge-commit-message.txt
    	rm svnmerge-commit-message.txt
    	

That basically sums it up. In addition to merging from branch to trunk, a developer can also merge from trunk to any branch. For more information, there is a detailed wiki page about svnmerge.py in the subversion wiki.

Happy merging!!! 

posted in
Add comment
Recent Entries
Categories

AJAX (13)
CCK08 (1)
MEL (16)
LAMS (4)
Tech (13)



Authors




Archive




Notifications
Icon of envelope You may request notification for Solution Grove Blog.


Syndication Feed
XML


Recent Comments
  1. Eamon Costello: thanks
  2. Dave Bauer: Using clickpass
  3. Caroline Meeks: Should we put this on Solutiongrove.com, .net, .info??
  4. Jong-Dae Park: How about redirecting users to setup password for elgg
  5. Caroline Meeks: Great job!
  6. Mark Tomizawa: Bandwidth (the human kind)
  7. Hamilton Chua: ns_zlib on OpenACS
  8. Hamilton Chua: Thanks Mark
  9. Mark Aufflick: svnmerge.py saves you the pain
  10. Hamilton Chua: Mosio, Yahoo Answers on Mobile ?



Technorati Blogs