CVS merge in Eclipse

Dejan Peretin bio photo By Dejan Peretin

Ever so often a need for merging CVS branches arises and since the task can be a bit touchy, writing down some basic concepts seems like a good idea. So here are a few basic steps the process boils down to.

Branching

Creating a branch is done with right clicking on a project -> Team -> Branch. Leave Start working in the branch checked so newly created branch will be checked out automatically. Common scenario is that people make some changes on their local version of the code and then realize that they do not want to commit it to the main branch. If you create a branch with uncommitted changes in your workspace, those changes will be available for committing to the branch.

Merging

Lets assume we are to do a merge of a HEAD branch onto some FEATURE branch (HEAD is the source branch and FEATURE is the target branch).

Procedure:

  1. Checkout the source branch, do a sync, make sure there are no changes between your local version of the source branch and the remote version.

  2. Tag the source branch. Give the tag a name that will provide information about the date of merging and branches that were involved in the merge. (eg. M_yyyymmdd_HEAD_FEATURE). Tagging is done with right clicking on the project -> Team -> tag as new version. The purpose of tagging at this point in the process is to avoid situations where somebody makes a commit while you are merging. If this happens, CVS will not be aware of the changes made in that commit.

  3. Checkout the target branch (right click on the project -> Team -> Switch to Another Branch or Version).

  4. Do the merge.
    • right click on the project -> Team -> Merge
    • Select the tag you created in step 2 (M_yyyymmdd_HEAD_FEATURE in this case) as Branch or version to be merged .
    • Select the tag you made in step 2 but in the previous merge (if this is the very first merge, select the version created at the branching point) as Common base version.
    • Select Preview the merge in the sync view option.
  5. Resolve conflicts. You can’t automate this step.
    • Non conflicting changes could be just copied over.
    • Make changes to conflicting files and mark them as merged.
  6. Commit all new changes. Make the commit message something like:
    • - merge changes HEAD -> FEATURE

Little tip at the end. If a FEATURE branch needs to be merged onto HEAD branch after some development period, its a good idea to merge HEAD branch onto FEATURE branch first. All conflicts will have to be resolved on a FEATURE branch which will make FEATURE to HEAD merge a trivial one.