Subscribe to our feed

Symfony Experts

Symfony Experts
If you have an urgent question for a symfony-related issue, this is the place to ask.


Stack Overflow

The old fashioned way


February 17, 2009 – 12:43pm SVN merge trunk changes to your branch

I always have to look up the documentation on how to merge a whole SVN branch to another. Today there were bug fixes to trunk of my project that I wanted to port into my branch. I expected this to be easy since I hadn’t made many changes to my branch, and no changes to the same files that were modified in the trunk.

Using Common Use-Cases as a reference, this is what I did:

From within my branch:

svn log

This displays the revision number for when my branch was created:

r23 | stereosv | 2009-02-17 11:42:28 -0500 (Tue, 17 Feb 2009) | 1 line
creating branch for xyz

Now I need to find out what revision number the trunk is at. Perfoming an “svn update” within the trunk shows me what version it’s at.

> svn update
At revision 25.

In my case the trunk is at revision 25… implying there were only two commits since the time I checked out my branch. Nice.

Now, it’s time to carry merge these changes into my branch. Back in my branch directory, it’s time to put these revision numbers to good use.

svn merge -r 23:25 svn+ssh://username@svnserver/home/username/svn/project/trunk

What this does is merge the changes that were made between revision 23 (when I created my branch) and revision 25 (the most recent revision of the trunk) in the trunk into my working copy.

Now, it’s time to check in my branch, with the updated changes from the trunk.

svn ci -m "Merged trunk changes r23:25 into my branch"

SVN 1.5 has made some improvements to the way merging works.. So check your SVN version with “svn –version” to make sure you are using the right syntax for your version.

Posted by in  Web Development   |  

14 Responses to SVN merge trunk changes to your branch

  1. Andrew Noyes says:

    I’m a command-line junky myself, but I find SVN almost too obnoxious (overhead-wise) to do from the CLI. I suggest you check out Versions or Cornerstone. Both are excellent. For diff, you can always use FileMerge if you have the Apple Developer Tools installed, or something like Changes or Araxis Merge. I personally prefer Changes.

    The merge predicament is a common one, so I look it up too almost every time I use it. However, I’ve adopted a work flow that dodges around it: rather than merging the trunk with my branch, I will simply update the working copy and diff the changes if necessary. Fortunately though, I work with basically no one, so I don’t have a big problem with this.

  2. Thanks for your work!


  3. Wayne Khan says:

    Thanks, this was really helpful! 🙂

  4. Pingback: Updating branch with changes from trunk. « Talueee's Blog

  5. Patrick says:

    Thanks for share. 🙂

  6. Aartist says:

    I was able to use this nicely.

    Thanks for the write-up.

  7. andres says:

    Nice. I use ‘svn log -l 1’ so i just get the last revision.


  8. Ezhil says:

    Thanks.very helpful 🙂

  9. Pingback: Subversion: merging updates in trunk to a branch – Lennart's weblog

  10. Erik says:

    For longer histories, just typing “svn log” in the branch can be overwhelming since the whole history is returned (at least with SVN 1.7.8). I found it very useful to type “svn log –stop-on-copy” when viewing the branch history: This way you will only get the log since the revision when you created the branch.

  11. I followed your steps. It seems to work from the command line output, but it is saying there are tree conflicts and I don’t actually see the files I am expecting to be there… Any tips on how to deal with this?

  12. Lokesh says:

    short and clearly explaind…thanks

  13. sha says:

    Can you improve this blog with more info on resolving the merge conflict ? like C, A+, S

    Conflict discovered in 'java/services/service/test/'.
    Select: (p) postpone, (df) diff-full, (e) edit,
    (mc) mine-conflict, (tc) theirs-conflict,
    (s) show all options:

  14. this dev1 says:

    Really useful.
    From a shell use ‘file://’ like this:

    svn merge -r 10:12 file:///home/username/repo/trunk