Merge across CVS branches with ease

Recently, I’ve been merging across CVS branches. Eclipse makes this a lot easier…if only I had known when I first started merging.

The Scenic Route

Let’s say you have a ‘prototype’ branch that you want to routinely merge back into HEAD. Here’s how our team used to do this type of merge:

  1. Checkout the ‘prototype’ branch in Eclipse.
  2. Tag the ‘prototype’ branch in Eclipse with the tag ‘merge_prototype_to_HEAD_20071006’.
  3. Create a patch using ‘cvs rdiff’ on the command-line between the two tags.
  4. Checkout the ‘HEAD’ in Eclipse.
  5. Apply the patch to ‘HEAD’.
  6. Resolve conflicts. This is painful, because Eclipse doesn’t offer a way to resolve the conflicts when you apply the patch. What I’ve done to resolve conflicts is have the patch window open on one machine, so I have the list of conflict files. On this same machine, I will compare the history on the destination branch, and also do the actual merge. I’ll have a second machine open for comparing the history on the source branch.
  7. Handle binaries. Since binary files are not saved in CVS patches, you need to create your own technique for generating a list of binaries (I use grep on the patch file), and you have to copy over the binary files.

Taking the Highway

Here’s what we do now:

  1. Tag the ‘prototype’ branch from the command-line, without having to checkout the branch, using ‘cvs rtag’ with tag ‘merge_prototype_to_HEAD_20071006’.
  2. Checkout HEAD.
  3. From the Eclipse menu, select ‘Team -> Merge’. This will display merge output in the ‘Synchronize’ view. This has the same features for resolving conflicts that are available when you do ‘Team -> Synchronize’. This handles binaries really well. If there’s a binary conflict, right-click on the binary, and select ‘Overwrite’ to select the one from the source branch, or select ‘Mark as Merged’ to keep the current version of the binary.
  4. Once all files are merged and all conflicts resolved, you can select ‘Team -> Synchronize’ to start committing.
It's only fair to share...
Share on FacebookGoogle+Tweet about this on TwitterShare on LinkedIn

Leave a Reply