Next & Previous

The rough guide to an easy SVN merge

SVN merges can be tricky. We use TortoiseSVN here at work, as do many other .Net development places, so that will be the tool of choice for this guide. This tutorial assumes the merge of a branch into the trunk. You should have both of these checked out on your machine already.

1. Update

This is a dead simple sanity measure. Check you’ve run SVN Update in both the trunk and the branch.

2. Check for uncommitted stuff

Go to SVN Commit in both the branch and the trunk, and make sure that you’ve committed everything you want to keep. In a moment, we’re going to revert all unversioned changes.

3. Clean up

In both branch and trunk, go to TortoiseSVN/Clean up... Tick:

This is why we made sure we committed anything earlier; we’re about to clean the working copy so that it is exactly the same as the server copy, losing any changes. If the revert fails for some reason, go to TortoiseSVN/Revert, tick all files, and let it run. Then repeat the Clean up.

4. Sync the trunk changes into the branch

This is the major step to save us from conflicts: the branch needs to track any changes in the trunk.

In the branch folder on your PC, go to TortoiseSVN/Merge...:

Now a lot of people will do a test merge, but I’ve found it a bit useless. It imagines conflicts which won’t really happen in the real thing, and also doesn’t let you do anything about them. Since you have a guarantee that all of your work is safe in either the trunk or the branch (and we can easily revert), just hit Merge.

5. Build and commit the branch

Check your branch still builds.

Now go to SVN Commit. You can use a message from Recent Messages in Tortoise, which will hopefully describe the changes which were rolled into your merge (although sometimes it doesn’t work). I like to leave a simple note that says “Sync trunk changes”.

6. Merge the branch into the trunk

In the trunk folder on your PC, go to TortoiseSVN/Merge...:

7. Commit the trunk

Go to SVN Commit and either use an auto generated message or something like “Merge branch into trunk"

You’re done

Key principles:

Hope this helps!