Subversion: Merging Changes from a Branch into the Trunk

We don’t branch or tag super often, usually just on major releases, experimental code, or not-yet-ready code. But sometimes you’ll have changes in a branch that you want to merge back into the main development trunk.

So assume your project’s trunk is at myproject/trunk.  You then create a branch for a major release in myproject/branches/1.0-release. After a few weeks, you have to fix a bug in the 1.0-release version of your project, so you make the changes to the /myproject/branches/1.0-release branch. Then you build, test, & deploy that fixed version to production or whatever.

But now you want to merge that fix into your trunk. The main thing to remember is that the only changes you want to merge are the ones you made after the branch was created. You don’t want to merge the entire branch into the trunk, otherwise you’ll end up merging old code (from the branch) into the trunk, too.

BTW you might ask why I use “branches” instead of “tags” in the above example. That’s because tags and branches are the same as far as SVN is concerned, and the main difference is that a “tag” is supposed to be a “snapshot” of your code that you don’t make changes to (i.e. a static archive), while a “branch” is a version of the code that people might change. Since there’s always a chance that we’ll need to make changes to a major release (without accidentally including any not-yet-ready trunk changes), all our major releases are branches, not tags.

Ok so enough of all that. Below are some links on this topic that I suggest you read.

  1. SVN Book Chapter 4. It’s a quick read, explains the principles, and shows the commands. You can skip through some of the beginning if you already know about branching, but sections “Copying Changes Between Branches” and “Common Use Cases for Merging” have good overviews on merging changes and branches. I’d suggest first reading the explanations and skipping the actual commands, so you know what’s going on from a high-level.
  2. SVN Branch Merging from Michael Sepcot. Nice easy SVN commands to follow, now that you understand what’s going on. If you’re using Subversion from a command line, that is.
  3. How to Merge using Tortoise SVN. If you’re a Windows developer, you’re probably using TortoiseSVN. This guide explains how to perform the merge. Remember that the changes are merged into your local copy, so you can confirm they’re ok and then commit them into SVN.

Happy merging!

0