Tuesday, December 11, 2007

Using branching in Subversion

For small changes a developer will typically work directly on the trunk, but for bigger changes the developer will typically work on a private branch. This is best done in the following way:
  • Create a branch (at the trunk-level) and name it something like aris-private-branch.
  • Select the part of the trunk's sub-tree that will be affected by the branch and svn switch that sub-tree to the new branch
  • Make changes locally and test them
  • Commit the changes to the branch
  • When all is done, merge the changes to the trunk:
    • svn switch back to the trunk's sub-tree
    • svn merge using the initial revision of the branch and the head revision of the branch
    • Commit the changes (it is prudent to check that you are not eliminated other people's changes that were done to the trunk while you were working on your private branch)
    • Delete the private branch (through the repo-browser)

For changes spanning a long time, it might be necessary to merge from the trunk to the branch to incorporate other developers' changes. In this case it is simplest to keep track of the revision number of the merge from the trunk so that next time only changes in the trunk from the last merge are merged to the branch.

No comments: