简体   繁体   English

Tortoise SVN 合并两个分支

[英]Tortoise SVN merge two branches

i'm trying to merge two branches with tortoise SVN.我正在尝试将两个分支与乌龟 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:".我尝试了“合并两个不同的树”选项,并在“From:”和“To:”中输入了两个分支。 I took the Head Revision on both.我对两者都进行了头部修订。 I left everything else to default (Merge depth: Working Copy, Compare whitespaces, everything else unchecked)我将其他所有内容保留为默认值(合并深度:工作副本,比较空格,其他所有内容均未选中)

In the From URL option, you should specify the branch to which you want to merge.From URL选项中,您应该指定要合并到的分支。

For example, assume that there are 2 branches, branch A and branch B , and you want to merge branch B to branch A .例如,假设有 2 个分支,分支A和分支B ,并且您想将分支B合并到分支A

  • In TortoiseSVN, click on Merge option and then select Merge two different trees option.在 TortoiseSVN 中,单击Merge选项,然后选择Merge two different trees选项。
  • In the From URL , please mention URL of branch A and in the To URL , mention URL of branch B .From URL ,请提及分支ATo URL ,在To URL ,请提及分支B URL。

This should merge branch B to branch A without losing any files.这应该将分支B合并到分支A而不会丢失任何文件。

Reference: found this statement here参考:在此处找到此声明

Merging in Subversion is always done locally .在 Subversion 中的合并总是在本地完成。 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).您有要合并到的分支(称为yours )、要合并的分支(称为theirs )和最后一个共同祖先(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.合并算法知道这一点,因为您的算法和 LCA 之间存在差异。 If there is difference between the LCA and theirs , that's considered for a change.如果 LCA 和他们的 LCA 之间存在差异,则考虑进行更改。

If I understand you have:如果我明白你有:

  • branch1 was taken from trunk. branch1取自主干。
  • branch2 was taken from branch1 . branch2取自branch1

What are you trying to merge?你想合并什么? Do you want to merge both branch1 and branch2 into trunk.是否要将branch1branch2合并到主干中。 This should be possible if you copied trunk into branch1 through Subversion and copied branch1 into branch2 through Subversion.如果您通过 Subversiontrunk复制branch1通过 Subversionbranch1复制branch2这应该是可能的。 This way, Subversion knows that the two branches are related in their history.这样,Subversion 就知道这两个分支在它们的历史上是相关的。

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.如果您创建了分支,使用 Windows 复制文件并添加了文件,则两个分支之间没有历史记录,合并会更加困难。

Is it okay to merge the changes of branch2 into branch1 ?可以将branch2的更改合并到branch1吗? If so, I'd do something like this:如果是这样,我会做这样的事情:

  • Checkout branch2结帐branch2
  • Merge branch1 into branch2 and commit those changes.合并branch1branch2并提交这些更改。 branch2 will have all the changes in branch1 . branch2将在所有的变化branch1
  • Checkout trunk结账trunk
  • Merge branch2 into trunk .branch2合并到trunk Trunk will now have all the changes in both branch1 and branch2 . Trunk 现在将在branch1branch2进行所有更改。

" 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.注意: output branch是指您要将更改合并到的分支。 While input branch refers to the branch whose changes you want to merge in the output branchinput branch指的是你想在输出分支中合并其更改的分支

  1. Take a clean working copy of the output branch获取output branch的干净工作副本
  2. Open the TortoiseSVN merge wizard (TortoiseSVN > Merge), and select the "Merge a range of revisions" option打开 TortoiseSVN 合并向导(TortoiseSVN > Merge),然后选择“Merge a range of revisions”选项
  3. In the URL to merge from field, enter the input branch在要合并的 URL 字段中,输入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 .在要合并的修订范围字段中,如果要合并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 TortoiseSVN在这方面很聪明,任何已经合并的修订都会变灰并标有已经合并的图标
  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解决所有冲突后,将更改提交到output branch

图 4.56。合并向导 - 选择修订范围

For further details refer to TortoiseSVN Docs on Merging有关更多详细信息,请参阅TortoiseSVN Docs on Merging

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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