Automatic branch merging with SVNMerge on Subversion

February 21, 2007




SvnMerge enables you to track which changes on another branch have been merged into your current working branch. This means that you won’t accidentally merge the same change twice. SvnMerge isn’t a trivial tool to use, so we’ll need to discuss how we are using it, and define some terminology.

Feature Branch: A branch that you are merging changes FROM. There can be more than one Feature Branch, gathering up features from multiple developers.

Target Branch: The branch that you are merging changes TO. There is generally only ONE Target Branch.

In this article, we are going to discuss how to use SvnMerge to track changes on one or more Feature Branches, into a single Target Branch. It is also possible to merge your Target Branch into one of the Feature Branches, but we won’t examine that.

SvnMerge works by storing within subversion, meta information about actions on your files/directories . By doing this it can tell whether a particular change has been merged from Feature to Target. However, because SvnMerge does not automatically commit this information, it is up to you to commit this info into Svn each time you perform an SvnMerge action. We will look into this specifics of that later.

Setting Up

SvnMerge is shipped with Subversion, but can also be downloaded from here: ; It’s a Python script, although there is a windows executable available too. If you use the Python script you’ll need the latest version of Python: ; Install Python from the installer, and put somewhere on your PATH.

Type –version to check that SvnMerge is installed correctly. It should display something along the lines of:



C:devTesttrunkmike2> --version
svnmerge r<unknown>
  modified: <unknown>Copyright (C) 2004,2005 Awarix Inc.
Copyright (C) 2005, Giovanni BajoC:devTesttrunkmike2>

Initialising SvnMerge

SvnMerge is used from the command line, so some familiarity with that is assumed. Some familiarity with the svn command-line tools is also assumed, although you can also see what’s going on using the TortoiseSvn GUI.

First we have to tell SvnMerge which changes have happened on this directory BEFORE the Feature Branch was created. This is a tricky bit. Open a command window and cd into the Feature Branch directory (e.g., c:\dev\f1222)


svn log

Note down the list of revisions before and upto the creation of the Feature Branch. For example, in this log output:



C:devTestbranchesmike2>svn log
r2616 | e151145 | 2006-12-06 12:25:01 +0000 (Wed, 06 Dec 2006) | 1 linecreating branch
r2615 | e151145 | 2006-12-06 12:24:33 +0000 (Wed, 06 Dec 2006) | 1 linecreated in trunk/

The versions in question are 2615-2616. You will also need the full Svn URL of your Feature Branch, e.g., ; You can get this by cd’ing into your Feature Branch directory and typing “svn info”. Now that we have this information, we can initialise SvnMerge. CD into the Target Branch directory, and issue this command: init -r2615-2616

where 2615-2616 is replaced with your versions, and the URL is replaced with your Feature Branch URL. If all goes well, you should get a message back like this:



property 'svnmerge-integrated' set on '.'

As mentioned earlier, you need to commit any changes created by using SvnMerge. SvnMerge creates a standard merge comment for you, in a file called svnmerge-commit-message.txt. If you issue the following command, you will check the changes into Subversion:



svn ci -F svnmerge-commit-message.txt

This should give you a result along the lines of



Sending mike2Committed revision 2625.

You must now delete the svnmerge-commit-message.txt file. SvnMerge requires that the branch it works on be free of uncommitted files. So do:



del svnmerge-commit-message.txt

SvnMerge is now initialised. Note that you only have to go through this process once for each branch whose changes you want to track.

Using SvnMerge

Once initialised, SvnMerge is relatively easy to use.




svnmerge avail

to show the list of available merges from all initialised branches.

To peform a merge, type: svnmerge merge -r<revisionNumber> where <revisionNumber> is the range of revisions that came up from svnmerge avail. Example flow:



C:devTesttrunkmike2>svnmerge avail

C:devTesttrunkmike2>svnmerge merge -r2624,2655
U    file2.txt

property 'svnmerge-integrated' set on '.'

C:devTesttrunkmike2>svn ci -F svnmerge-commit-message.txt
Sending        mike2
Sending        mike2file2.txt
Transmitting file data .
Committed revision 2656.

C:devTesttrunkmike2>del svnmerge-commit-message.txt

Multiple Feature Branches

SvnMerge is capable of integrating from more than one Feature Branch. To do this, simply perform the Initialisation against each Feature Branch in turn. When using “svnmerge avail” or “svnmerge merge” you need to add the “-S” parameter, which you use to specify the path or URL. If you are making many integrations from multiple branches, it may be worth creating some environment variables containg the Feature Branch URLs.

Uninitialise Merge Tracking or Changing the Revision Range

It is possible that you want to switch off merge tracking on a branch. It is also possible that you will enter the wrong range of revision when doing an “svnmerge init”. In both cases you can call “svnmerge uninit” in the Target Branch directory, adding the -S <branch url> parameter if you have multiple feature branches. Once you have done the uninit, you will need to do an “svn ci -F svnmerge-commit-message.txt”. You can then run another “svnmerge init -r<range-range2> <url>” as before.


4 Responses to “Automatic branch merging with SVNMerge on Subversion”

  1. sandrar said

    Hi! I was surfing and found your blog post… nice! I love your blog. 🙂 Cheers! Sandra. R.

  2. Ronald said

    Thanks for sharing the useful information.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: