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:
- Checkout the ‘prototype’ branch in Eclipse.
- Tag the ‘prototype’ branch in Eclipse with the tag ‘merge_prototype_to_HEAD_20071006’.
- Create a patch using ‘cvs rdiff’ on the command-line between the two tags.
- Checkout the ‘HEAD’ in Eclipse.
- Apply the patch to ‘HEAD’.
- 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.
- 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:
- Tag the ‘prototype’ branch from the command-line, without having to checkout the branch, using ‘cvs rtag’ with tag ‘merge_prototype_to_HEAD_20071006’.
- Checkout HEAD.
- 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.
- Once all files are merged and all conflicts resolved, you can select ‘Team -> Synchronize’ to start committing.