Question

i'm trying to merge two branches with tortoise SVN. Both branches have been changed since they diverged. If i merge them, only the changes of one of them obtain and those of the other will be overwritten. But i want the latest change of every file (We have not been working in the same files).

I tried the option "Merge two different trees" and entered the two branches in "From:" and "To:". I took the Head Revision on both. I left everything else to default (Merge depth: Working Copy, Compare whitespaces, everything else unchecked)

Was it helpful?

Solution

In the From URL option, you should specify the branch to which you want to merge.

For example, assume that there are 2 branches, branch A and branch B, and you want to merge branch B to branch A.

  • In TortoiseSVN, click on Merge option and then select Merge two different trees option.
  • In the From URL, please mention URL of branch A and in the To URL, mention URL of branch B.

This should merge branch B to branch A without losing any files.

Reference: found this statement here

OTHER TIPS

Merging in Subversion is always done locally. The branch you want to merge to should be checked out with a clean checkout. That is, it should be up to date with no local changes. You then merge the other branch into it and commit your changes.

A Merge is not a duplicate of a particular branch. Merging is usually a three way operation. You have the branch you're merging into (called yours) the branch you're merging from (called theirs), and the last common ancestor (LCA). That last one is important.

If a change took place on your branch, it's not touched during the merge process. The merge algorithm knows this because there's a difference between yours and the LCA. If there is difference between the LCA and theirs, that's considered for a change.

If I understand you have:

  • branch1 was taken from trunk.
  • branch2 was taken from branch1.

What are you trying to merge? Do you want to merge both branch1 and branch2 into trunk. This should be possible if you copied trunk into branch1 through Subversion and copied branch1 into branch2 through Subversion. This way, Subversion knows that the two branches are related in their history.

If you created the branch, used Windows to copy the files, and added the files, you have no history between the two branches, and merging is more difficult.

Is it okay to merge the changes of branch2 into branch1? If so, I'd do something like this:

  • Checkout branch2
  • Merge branch1 into branch2 and commit those changes. branch2 will have all the changes in branch1.
  • Checkout trunk
  • Merge branch2 into trunk. Trunk will now have all the changes in both branch1 and branch2.

"Merge two different trees" option is useful when you're trying to make one branch look exactly like another branch.

If instead you want your output branch to contain changes from both the branches, you should use the "Merge a range of revisions" option.

Steps to use the Merge a range of revisions option:

Note: output branch refers to the branch you want to merge your changes into. While input branch refers to the branch whose changes you want to merge in the output branch

  1. Take a clean working copy of the output branch
  2. Open the TortoiseSVN merge wizard (TortoiseSVN > Merge), and select the "Merge a range of revisions" option
  3. In the URL to merge from field, enter the input branch
  4. In the Revision range to merge field, select 'all revisions' if you want to merge all the revisions of the input branch. If you want to merge specific revisions only, select 'specific range' and use the 'Show log' button to choose the revisions. TortoiseSVN is smart in this regard, and any revision that has already been merged will be greyed out and marked with an Already merged icon
  5. Select the Merge options on the next screen. The default options are good enough
  6. Use the Merge button to perform the merge. Conflicts (if any) will pop up, asking you to choose a resolution
  7. After resolving all conflicts, commit the changes to your output branch

Figure 4.56. The Merge Wizard - Select Revision Range

For further details refer to TortoiseSVN Docs on Merging

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top