"How to" SVN Merge with TortoiseSVN

image Ok, I have the hardest time remembering the "FROM" and "TO" semantics when merging in SVN.  So, here's a quick and dirty summary on merging in TSVN.

Suppose, you have a branch feature that you'd like to merge back into the trunk.

If there have been no changes to the trunk since you've been working on your branch, you can simply follow the steps below to merge your branch to trunk (branch -> trunk).

However, if there have been changes to the trunk while you've been working on your branch, then you should:

  1. First, merge trunk to branch (trunk->branch) to update your branch with the latest trunk changes.
  2. Then merge your new features from branch to trunk (branch->trunk).

Merge branch to trunk (branch->trunk)

  1. Commit all code in your working directory.
  2. Switch your working directory to the trunk:

    image image

  3. Next, Merge...
    image

  4. In the merge window, we need to make sure we are going "FROM" the trunk "TO" our branch.  The reasoning behind this is that we are doing a DIFF between the trunk and the branch.  Or, starting "FROM" the trunk's current state "TO" our branch's state.  The trunk is the starting point for the branch changes.

    image
  5. Now that the diff has been calculated, the results are stored in your working directory. You'll need to commit these results into  the /trunk to finalize the merge. 

    image

 

 

Merge trunk to branch (trunk->branch)

  1. Commit all code in your working directory.
  2. Make sure that your current working directory is your branch.
  3. Next, Merge...

    image
  4. The "FROM" text box should be the URL to the /trunk.  Why isn't it the URL to the branch?  Well, your branch doesn't have the changes that you're looking for in /trunk because we're trying to update our branch with changes in the trunk.  Effectively, what we want to do is perform a DIFF between the last time your branch was synchronized with the trunk and the head version of the trunk with the latest changes.  This is why "FROM" URL is set to /trunk and the revision number is set and the "Use 'FROM' URL" is set with "HEAD" revision.

    In my case below r25 was the last time the base of my branch was synchronized with the trunk.  I want to "REPLAY"/"DIFF" all changes that happened from the time my last branch (r25) was synchronized with the base of the "/trunk" up "TO" the current "HEAD reversion".  The result of this merge should be stored in my current working directory (which points to my /branch/cowboy).

    image
  5. Once the merge happens, you're branch should now be synchronized with the /trunk.  You'll want to "Commit" the result of the diff and add a special note in the message that indicates what revision you're working copy is based on.

Hope that helps!

Brian Chavez

 

PS: Here are some other useful links on merging with SVN:

Comments

# re: "How to" SVN Merge with TortoiseSVN
Gravatar Just wanted to say thanks, this info helped me a lot. I use Subclipse, but the idea is the same. The wording in the dialog is confusing to me, and the difference between t->b and b->t threw me for a loop, but I got it now =)

Thanks for the good post!
Left by Ethan on 10/7/2008 7:04 AM
# re: "How to" SVN Merge with TortoiseSVN
Gravatar Thank you for the excellent explanation.
Left by Kim on 1/28/2009 5:56 AM
# re: "How to" SVN Merge with TortoiseSVN
Gravatar Nice and Simple,Thanks
Left by atechgeek on 4/8/2009 2:02 PM
# SVN Merge was quite easy
Gravatar Thanx. This was easy and clean.

However, in my case, my SVN Repository is hosted on a Web Server. To add to it, I had to merge the branch of a colleague while I was working on the mainline. After quite a few trials, finally, checked-out the branch, merged the branch copy with the mainline (trunk->branch). Then i did an export of the merged branch copy, and copied the exported copy over to my mainline copy. ;) I know this is dirty, but I could keep my sanity with what was happening.

Kudos Chavez. Keep up the good work!

Sridhar
Left by Sridhar on 4/27/2009 3:41 AM
# re: "How to" SVN Merge with TortoiseSVN
Gravatar One thing I don't understand is how you came up with the revision number 25 (last time the base of my branch was synchronized with the trunk)? Did you just remember that or can you get it from subversion somehow?
Left by Chung on 6/16/2009 12:39 PM
# re: "How to" SVN Merge one particular change with TortoiseSVN
Gravatar How to merge a single change from branch to trunk using SVN.
Left by Rohit on 7/1/2009 2:11 AM
# re: "How to" SVN Merge with TortoiseSVN
Gravatar @Chung:

I had the same problem, and then I saw TortoiseSVN added a property to the working copy directory(svn:mergeinfo) with the revision range.
Left by Kevin on 12/23/2009 6:34 AM
# re: "How to" SVN Merge with TortoiseSVN
Gravatar Excellent!!
Left by Robrecht on 3/12/2010 12:43 AM
# re: "How to" SVN Merge with TortoiseSVN
Gravatar Awesome!!! It did help a lot....

Thanks,
--Atul
Left by Atul on 3/15/2010 4:15 PM
# re: "How to" SVN Merge with TortoiseSVN
Gravatar Thanks, very much!! This is perfectly clear. Have bookmarked this page for future use. Wow! Thanks again.
Left by Greg on 4/12/2010 12:03 PM
# re: "How to" SVN Merge with TortoiseSVN
Gravatar no BS just good advice. thanks a bunch.
Left by happydeveloper on 11/19/2010 6:00 AM
# re: "How to" SVN Merge with TortoiseSVN
Gravatar It is not possible to merge to/from a branch if you don't have permission to the entire "/branches" directory in SVN and not just the permission for the individual branches...


Is this true ?
Left by HarKrish on 2/4/2011 9:17 PM
# USING SVN BRANCHES
Gravatar To work with branches in SVN, using Tortoise, follow the procedure below: 1. Open the SVN repository browser 2. Right click on the folder you want to branch and click Copy to 3. Enter in the the name of the new branch you want to add. Eg. ........
Left by Confluence: TRAISI on 4/10/2011 3:46 PM
# re: "How to" SVN Merge with TortoiseSVN
Gravatar great help. thanks for this.
Left by gjpanam on 5/23/2011 4:43 AM
# re: "How to" SVN Merge with TortoiseSVN
Gravatar This document is not up to date. Could you please update it to have screenshots from the latest version of tortoise svn.

Thanks.
Left by Doug on 7/25/2011 2:55 PM
# re: "How to" SVN Merge with TortoiseSVN
Gravatar Awesome! Simple and straight forward. It saved my time. Thank you very much
Left by Deepa on 8/3/2011 9:24 AM

Leave Your Comment

Title*
Name*
Email (never displayed)
 (will show your gravatar)
Url
Comment*

Please add 7 and 1 and type the answer here:

Preview Your Comment.