Merging Branches with Subversion using CLI and FileMerge
On small projects I usually work right out of trunk to avoid the need to merge, but when working in teams to implement features that will be released separately creating a branch or two is the way to go. The only problem with working with branches is that you have to merge your code periodically in order to avoid nightmares. Here are the steps that I use to to a simple merge between a development branch and trunk. If there are better ways or if I missed something please let me know, but these is what worked for me.
1) First svn update local working copy (both trunk and branches)
2) Change directory to the branch (branches/development)
cd /Users/Paul/Documents/test_svn/repo/
3) Run a merge command similar to the one below as a dry-run to see if everything looks OK:
svn merge --dry-run -r 4:HEAD file:///Users/Paul/Documents/test_svn/repo/trunk
4) Then if you are satisfied with what you see, you can run the real command which will actually update your working copy with the merged files from trunk.
svn merge -r 4:HEAD file:///Users/Paul/Documents/test_svn/repo/trunk
5) If you have conflicts (lines that start with “C”,) then its time to merge the changes. I use FileMerge and merging the right version with the working version and then I save the merged file and then
6) Checkin all of the merges files by doing a svn commit.
7) No change directories to the Trunk working copy and run the following as a dry run.
svn merge --dry-run -r 4:HEAD file:///Users/Paul/Documents/test_svn/repo/branches/development
8) Then if everything checks out, you do the real merge:
svn merge -r 4:HEAD file:///Users/Paul/Documents/test_svn/repo/branches/development
NOTE: when merging the branch back into trunk, you must use the same revision number as the you did when you merged trunk into the branch, or the revision number of the commit made after the last merge from trunk to your branch.
If you not done any regular merges, which you should do BTW, to avoid really hairy merges, then your revision numbers for both merges will be the same.
9) Resolve any conflicts.
10) Checkin all of the merges files by doing a svn commit.
Now your two branches are synced up! Yeah! Happy merging!
The key is making sure you keep track of revision numbers and merging, one way to do that is to create a tag with a date or sequence number. Also, you can look into the history by using the svn log .
