Doing a merge between two branches in subversion
UPDATE: I've fixed a typo in the proper way to do the merge, I wrote -r 210:240 but it should be -r 127:240 (from the point where the branch is created to the latest revision)
I would like to write some lines about this, as it took some time for me to realize how to do it correctly. Let me explain it with an example.
In this repo we have the usual trunk, branches and tags repo layout. Let's forget about tags, as we are not going to use it for the purpose of this post. We start to use the repo with the initial import (r1, aka revision 1) inside the trunk. Then we continue adding more changes to the code, up to revision 127 (r127), where we create a new branch (called mybranch) using the svn copy command (r128).
And now is when the problem happens. Imagine we need to unify the development process in only one branch of development. As our main development was inside the mybranch branch we try to get the changes made into trunk (since we created mybranch) back into mybranch itself.
$ svn merge svn+ssh://svn.myproject.org/svn/trunk .
(you have to be in a clean checkout of the branch)
The problem with that is that it doesn't work at all. It will do some strange merges (for example, it will try to merge back things from revisions like r29 which changes are already in mybranch).
So, we try another approach:
$ svn merge svn+ssh://svn.myproject.org/svn/branches/mybranch \ svn+ssh://svn.myproject.org/svn/trunk .
(you have to be in a clean checkout of the branch too)
This doesn't work either, it will put your working copy into r210, deleting all the changes specific from mybranch...
So, what else could we do? Well, we can do it just using the -r flag to force the revisions between we want to do the merge, just like this:
$ svn merge -r 127:240 svn+ssh://svn.myproject.org/svn/trunk .
(once again, you have to be in a clean checkout of the branch)
This will merge back the changes made in trunk into mybranch.
And, now to end my post, just a curious annotation about the Subversion book. If you search for subversion book in google and you click in the direct links (Multi-page html for example), you will access the 1.4 version of the book, this one, where you can find the proper way to do the merge. But, if you go to the main subversion book page, you only have access to the nightly build and older versions of the book, where you can find the other two options I've mentioned...