Merging different SVN branches can be overwhelming... But once you have understood a few principles, the tasks become fairly easy. We will describe in this page a real case scenario.


When ImpressCMS 1.0 Beta was released, we created a new branch in the SVN : branches/impresscms_1.0. The goal of this branch was to hold any bug fixing that would be needed during the 1.0 release cycle. In the meantime, development of ImpressCMS 1.1 kept on going on in the SVN trunk. More information can be found about Release Procedure and Release Cycle.

The problem (or is it a problem?)

Now, the challenge (more than a problem) occurs when ImpressCMS 1.0 final was released. We needed to merge the bug fixing which occurs in the impresscms_1.0 branch back in the trunk. And this is something that will need to be done every time a final version is released: the release branch will be merged back in the trunk.

So what to do ?

We will use TortoiseSVN, a Windows SVN client application throughout this example. Please note that all of this also applied to any other SVN client, even the command line, but of course, the exact way to do it might change a little bit, but the concepts are exactly the same. First, we need to have a working copy of the trunk: Right click > SVN Checkout > core/trunk. Doing that, we will have a working copy of the latest code in the trunk. This is is where we will do the merge. So let's do it: Right click > Tortoise SVN > Merge : This will bring up the following screen: Clicking on the Merge button will start the merging process. It is very important that you understand the following: the merge actually happens on your working copy, and not on the SVN repository. It is only when actually committing your working copy then the changes will be added on the SVN repository. But we will get there.... The merge process can take a few minutes. Once it is done, you will see the result of the merge in TortoiseSVN window: It may be a good practice to select all the lines in that window and copy-paste it in a text file so you can come back to it later. When actually merging impresscms_1.0 branch to the trunk, we posted the merge results in the forum so we keep a log of it for future reference.

Resolving conflicts

The result of the merge will most likely contain some conflicted files. Those conflicts need to be resolved one file at a time. In our actual example, the file htdocs/kernel/user.php is conflicted. Let's have a look at the containing folder: We can see 4 files:

  • user.php: this is the actual merged file, which has conflicts, so it cannot be left like this
  • user.php.merge-left.r603 : this is the file as it was at oldest revision specified in the merge, which is, in our case, revision 603
  • user.php.merge-right.1270: this is the file as it was at the most recent revision specified in the merge, which is, in our case, revision 1270
  • user.php.working: this is the file as it was in our working cpy, before we did the merge

So in our case, what we want to do, is to use a file comparison tool to compare the latest revision (1270) with our working copy. We manually merge the changes in user.php.working, then delete all the 3 other user.php files and finally, rename user.php.working into user.php. And we are done with user.php. Then we need to repeat the process with every conflicted file that our merge produced.

Committing the changes

Once we have resolved all our conflicts, we need to commit the changes. So, in the root of our working copy: Right click > SVN Commit. It is very important that your log message contains the revision range that was used in your merge. For example: Merging branches/impresscms_1.0 back into the trunk, revision 604 to 1223. Merge log can be found here:

How to prevent too many conflicts ?

In order to prevent too many conflicts to be created, it is good practice to merge the branches more frequently. For example, if you develop a new feature on branch XYZ, be sure to merge the trunk over your branch often during your development. Doing so, you will always have the latest code on your branch. And when the time comes to merge your branch back in the trunk, the difference between your branch and the trunk will only be related to YOUR changes and not changes that have been done in the trunk during your development. Category: Development Category: Getting Started <[Languages ]>

Last modified on 2019/5/20 by fiammybe
The comments are owned by the poster. We aren't responsible for their content.