简体   繁体   中英

Merging trunk to branch

This is the first time trying to merge the latest in the trunk Head to my branch. I just want to get any latest updates from other developers on my team into my branch. I am using Subversion 1.6.7. So in the Merge dialog I selected the option "Merge 2 different trees".

My question is this:

My branch's latest revision is 358 and the mainline trunk is 357. So when I do a test merge, it deletes anything new in 358 (my branch). Should I be going from my trunk to branch instead of from branch to trunk in this case since my branch has a higher revision number? I know in the examples on various blogs, they say to go FROM branch TO trunk but in my situation the branch has the higher revision number.

alt text http://elbalazo.net/post/repobrowser.jpg

alt text http://elbalazo.net/post/merge.jpg

Now during the test merge, I don't see why it's deleting those files that don't exist in my trunk (that I had added new to my branch during development):

alt text http://elbalazo.net/post/mergeoptions.jpg

alt text http://elbalazo.net/post/revisiongraph.jpg

alt text http://elbalazo.net/post/deleted.jpg

Now lets do the reverse...which is how I think it should go (Because then I'd be going FROM a revision that's lower (357) TO a revision that's higher (358). So here it is going FROM mainline trunk TO my branch:

alt text http://www.elbalazo.net/post/mergdialog_trunk_to_branch.jpg alt text http://www.elbalazo.net/post/testmerge_trunk_to_branch.jpg UPDATED AFTER COMMENTS BELOW:

Ok, so when I try trunk-to-trunk, here's what I get:

alt text http://www.elbalazo.net/post/merge_trunk_to_trunk.jpg

alt text http://elbalazo.net/post/testmerge_trunk_to_trunk.jpg

Tortoise merging is very good, but there's a trick to it you have to know.

When merging, firstly use the top radio button option (merge a range of revisions) and always merge into the destination. So, right click on the destination working copy, select merge, then edit the URL in the merge dialog so the From: field contains the branch you want to take changes from.

Its a bit backwards when you first see it, but it actually makes more sense once you've understaood what's happening - that you're taking all the changes in the URL on the merge dialog, and applying them to your working copy. That's the trick to understand - you're not merging the files (like you would manually) but you're re-applying the changes that were made to the source branch.

Use the 'show log' button to select the revisions you want. If there is mergeinfo (ie previously merged revisions) they'll show as grey.

The other part of all this is that SVN isn't too good on handling tree conflicts - if you've added or deleted a directory, SVN will ask you what you meant to happen (ie a tree conflict). All you have to do is resolve the directory and select the ones that actually were deleted or added. It does this because it cannot be sure a file was deleted (or added) or just renamed.

I merge all the time now - it's really easy - but I don't think I've ever used the other two merge options on the first dialog. Always merge from the URL to your working copy; once the merge is complete you can review the results and commit them once you're happy.

I don't think you're selecting the right URL to merge into. You should right click on the branch you want to merge into, select merge, and then select two revisions along the "trunk" branch from which to merge.

Should I be going from my trunk to branch instead of from branch to trunk in this case since my branch has a higher revision number?

The revision number shouldn't determine whether you go from trunk to branch or vice versa. What is important is: what do you want to merge? Do you want to move the changes created in the branch back to trunk, or do you want to move changes from trunk to the branch?

If you want to move changes from the branch to the trunk (which is usually what you want, if you are using branches for "what they are intended for") then merge from the branch, r345 - 358 into trunk. Otherwise, do it the other way around.

EDIT : What you are doing in the screenshot above is taking the delta FROM rev 358 TO rev 357 and merging this into your working copy. Since you added files in commit 358 and 357 - 358 < 0, the delta will do the opposite operation, that is, removing the files.

If your intent is to just merge all trunk changes to your branch that aren't already there, you shouldn't need to specify a revision range at all (explained after the steps)

I believe this should be your workflow:

  • Right click on a clean (no modifications) working copy of your branch
  • Select 'Merge a Range of Revisions' and hit Next
  • Fill in 'URL to merge from' with the URL to trunk and hit Next (do not fill in the revisions field)
  • ... test merge or do the merge.

Since you're on 1.6, which is a version of Subversion with merge tracking, not specifying a revision range will use Subversion's merge tracking and will merge any revisions that aren't already marked as merged in the branch.

If this is the first time you've merged anything from trunk to the branch, that means anything from the revision after the one you created your branch from through the HEAD revision of trunk will be merged into your branch workspace, and then when you commit that merge will be recorded. If you decide to sync your branch again a week later, using the same steps it would only merge any revisions in trunk that weren't merged previously.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM