2008-11-03

Branching and Merging in Subversion

Subversion (and Subclipse as my current UI to it) has a somehow tricky branching and merging technique, I've tried it for some time and the only way I managed to do it is by:

  1. The main trunk is branched using Team -> Branch/Tag (this initiates a Commit which is recorded in context to the branch, not in the main trunk; you can get its revision number by showing the history of the project linking to the branch or the main repository in the SVN Repositories view, but not the project linking to the trunk)

  2. You can select to switch to the branch in the same project, or keep this project linked to the trunk and checkout another project linking to the new branch
  3. Edits can be done independently from both the trunk and the branch where the commits don't conflict (as they are in fact different files)
  4. When you need to incorporate a change that has been done in the trunk but not in the branch (like a bug fix or to keep the branch up with the trunk), the Merge command can be used:
    • Select the project containing the branch
    • Select Team -> Merge
    • In the "From" group, press the select button beside the revision number
    • In the available revisions select the revision you branched at (the Commit of the branching order)
    • In the "From" group, press the Select button beside the URL text box
    • Select the trunk folder
    • In the "To" group, check "Merge to HEAD revision" to incorporate all the changes done in the branch, from its creation to the current most up-to-date revision
    • This will create a modified working set locally (the project linked to the branch will need to be committed)
    • At this stage, you need to update the project first (using Team -> Update) before the modified files can be committed
    • Finally, select Team -> Commit to publish the merged files into the branch
  5. In the reverse direction, when you need to merge back changes from the branch into the trunk (where edits has been done in both the branch and the trunk), all you need to do is to select the project containing the trunk and select the branch as your "From" URL, you still need to select the revision number of the Branching commit (for all the changes you committed to the branch to be included and not just the newer or latest ones)  

I find a special shortcoming in the Subversion branching and merging system; when merging, it doesn't merge the changes in its revision number, meaning that if you did changes to the branched files in revisions 105,106,107 & 108 to the branch, and then merged and committed the changes to the trunk in revision 109, you will only see all of the changes suddenly occur to the file in revision 109 and later, not in an incremental way as it should be.

This is not a major shortcoming, as you can always return to the branch and check its changes in the revisions it was committed in, but it is still an unintuitive solution.

No comments: