‘How to’ SVN Merge with TortoiseSVN
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:
- First, merge trunk to branch (trunk->branch) to update your branch with the latest trunk changes.
- Then merge your new features from branch to trunk (branch->trunk).
Merge branch to trunk (branch->trunk)
- Commit all code in your working directory.
-
Switch your working directory to the trunk:
-
Next, Merge…
-
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.
-
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.
Merge trunk to branch (trunk->branch)
- Commit all code in your working directory.
- Make sure that your current working directory is your branch.
-
Next, Merge…
-
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).
- 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
Ethan
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!
Kim
Thank you for the excellent explanation.
atechgeek
Nice and Simple,Thanks
Sridhar
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
Chung
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?
Rohit
How to merge a single change from branch to trunk using SVN.
Kevin
@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.
Robrecht
Excellent!!
Atul
Awesome!!! It did help a lot….
Thanks,
–Atul
Greg
Thanks, very much!! This is perfectly clear. Have bookmarked this page for future use. Wow! Thanks again.
Richard
Thanks a lot, this finally made me understand how merging is done.
Jimmy
Interesting. But what about a brnach where you don’t want trunk changes to be merged into? i.e. the branch is for a specific feature set that should always be merged into trunk as the ongoing version. However in this case the branch represents the trunk at the original point in time of branch creation plus the new feature code specific to that branch. What are the risks on only doing a branch->trunk merge in this case? i.e. is it possible the merge would remove some of the new trunk code included as normal trunk development in the shared files?
Pete
Thanks! You saved me a lot of trouble.
I tried the TortoiseSVN docs but they are so vague.
tenh
Youlet me know more features SVN
thanks you
Ankeet
Thanks! Helped instantaneously!
Dax
Very good one, simple & perfect for a tutorial. I will give that to my dev
Muralidhar
Nice explanation with images. Is this same we can follow for SVN? Not for TortoiseSVN. Or any other procedure to follow?
Marta
Many thanks. You saved me a lot of research.
Srilatha
Thank you. This article helped me a lot.
Leave a comment
Your email address will not be published. Required fields are marked *