简体   繁体   English

SVN合并分支机构

[英]SVN merging branch-trunk-branch

I've done something stupid. 我做蠢事。 I've merged trunk into my branch for synchro and commited, and than merged my branch to trunk without -reintegrate option and commited. 我将中继合并到分支中以进行同步和提交,然后将分支合并到没有-reintegrate选项并提交的中继中。 Of course my branch is still in development process and I need it but I'm getting 当然,我的分支机构仍在开发过程中,我需要它,但是我正在

svn: E195016 ...Reintegrate can only be used if revisions x throug y were previously merged from " http://some.pl/trunk " to the reintegrate source, but this is not the case Missing ranges ... svn:E195016 ...仅当先前将修订版x throug y从“ http://some.pl/trunk ”合并到重新整合的源中时,才可以使用重新整合,但不是这种情况。

unfortunately trunk went forwardfrom that time, so my branch isn't up to date. 不幸的是,从那时起,行李箱一直向前行驶,所以我的分店不是最新的。

What's the best solution to fix it? 修复此问题的最佳解决方案是什么?

Did you just do that? 只是那样做吗? If so, you can use svn merge to unmerge your changes. 如果是这样,您可以使用svn merge取消合并更改。 Let's say you merged branch to trunk in Revision 1234: 假设您在版本1234中将分支合并到中继:

$ svn co $repo/trunk
$ cd $trunk
$ svn merge -c -1234 .   # Removes the merge that took place in revision 1234

Let's understand what happens when you merge trunk to branch and branch back into trunk: 让我们了解将主干合并到分支并分支回主干时会发生什么:

When you merge trunk to branch, you are doing a three point merge . 当您将干线合并到分支时,您正在执行三点合并 That is, you're looking at the branch, the trunk, and the most recent common ancestor (MRCA) of the two development streams. 也就是说,您正在查看两个开发流的分支,主干和最新的共同祖先 (MRCA)。 You're looking not only for the differences between the file on branch and trunk, but the changes that took place on trunk as compared to that most recent common ancestor . 您不仅在寻找分支和主干上的文件之间的差异,而且还在寻找与最近的共同祖先相比在主干上发生的更改。 I don't want trunk and the branch to match, I want the changes from MRCA to trunk to be applied, and to ignore the changes that have taken place from MRCA to the tip of that branch. 我不希望主干和分支匹配,我希望应用从MRCA到主干的更改,并且忽略从MRCA到该分支尖端的更改。

Subversion uses svn:mergeinfo to track what was and wasn't merged into your branch from trunk. Subversion使用svn:mergeinfo跟踪从主干合并到分支中的内容。 It can use this to figure out what changes you no longer need to move into your branch. 它可以使用它来找出不再需要进入分支的更改。 This way, your branch may have changed something previously merged, and you don't want to reimport from trunk. 这样,您的分支可能已更改了先前合并的内容,并且您不想从中继重新导入。

Now, let's look at merging from the branch back into trunk. 现在,让我们看一下从分支合并回主干的过程。 If I look at trunk, I see nothing from my branch has been merged into trunk. 如果查看主干,则看不到分支中的任何内容已合并到主干中。 After all, I've just been doing trunk->branch merges. 毕竟,我只是在做trunk-> branch合并。 If I did a standard merge, all changes that took place on my branch, will be considered. 如果执行标准合并,则将考虑在分支上进行的所有更改。

This even includes changes on my branch that I did on trunk, and then merged to my branch. 这甚至包括我在主干上所做的分支更改,然后合并到分支。 After all, Subversion has no real way of knowing this. 毕竟,Subversion并没有真正了解这一点的方法。 There's nothing on the trunk that shows this merge. 中继上没有任何内容显示此合并。

However, I usually want my trunk and branch to agree at this point. 但是,我通常希望此时的主干和分支都同意。 (Assuming I did a final merge from trunk to branch before I did the reintegration). (假设我在进行重新整合之前完成了从主干到分支的最终合并)。 Therefore, you want to do a two-point merge: You want to compare your branch version with the trunk, and after the merge, the version on the trunk should look like what it does on the branch. 因此,您要进行两点合并:您想将分支版本与主干进行比较,合并之后,主干上的版本应类似于分支上的版本。

In older versions of Subversion, this is what the --reintegrate parameter did. 在较旧版本的Subversion中,这是--reintegrate参数所做的。 It forced Subversion to use a two-point merge instead of a three point merge. 它迫使Subversion使用两点合并而不是三点合并。 However, newer versions of Subversion now automatically understand when to do a reintegration merge. 但是,新版本的Subversion现在可以自动了解何时进行重新集成合并。

So, what's the issue with the branch after a reintegration? 那么,重新整合后分支机构又有什么问题呢?

  • Revsion 99 : You merge from trunk to branch and commit your change. 版本99 :您从主干合并到分支并提交更改。 On your branch, ` svn:mergeinfo shows that everything on trunk up to Revision 99 has been merged into the branch. 在您的分支上,` svn:mergeinfo显示,直到修订版99的中继上的所有内容都已合并到分支中。
  • Revision 100 : You commit your merge from trunk into your branch. 修订版100 :您将合并从主干提交到分支。
  • Revision 100 : Still on Revision 100, you do a checkout of your trunk. 修订版100 :仍在修订版100上,您对中继进行检出。 You want to do your reintegration merge from your branch to trunk. 您想要从分支到主干进行重新集成合并。
  • Revision 100 : You now do your reintegration merge. 版本100 :您现在进行重新整合合并。 You see on your trunk that svn:mergeinfo says that all revisions from trunk up to Revision 100 have been merged into your trunk. 您在主干上看到svn:mergeinfo表示从主干到修订版100的所有修订都已合并到您的主干中。
  • Revision 101 : You commit your trunk merge. 修订版101 :您提交了中继合并。
  • Revision 102 : You make a change and realize this should also be put into your branch. 修订版102 :您进行了更改,并意识到这也应该放在分支机构中。

Now, let's checkout revision 102 on your branch, and do that merge. 现在,让我们在分支上签出修订版102,然后进行合并。 What does that svn:mergeinfo say? svn:mergeinfo说什么? It says that all revisions from trunk up to revision 99 have been merged into my branch. 它说从主干到版本99的所有修订都已合并到我的分支中。 What is Subversion going to do? Subversion会做什么? It will want to merge the changes from revision 100, 101, and 102 into your branch. 它将要合并版本100、101和102中的更改到您的分支中。

But wait a second! 但是请稍等! Revision 100 did not happen on trunk. 修订版100未在主干上发生。 It happened on the branch. 它发生在分支上。 That's okay. 没关系。 Revision 102 includes that change you want on the branch. 修订版102包含您要在分支上进行的更改。 But, revision 101 is the merge you did from the branch back onto trunk. 但是,修订版101是您从分支回到主干的合并。 Subversion is going to attempt to merge all of the changes I originally did on my branch and merged into trunk back onto my branch! Subversion将尝试合并我最初在分支上所做的所有更改,然后再合并到主干中, 回到分支上! This is not good. 不是很好。

What to do? 该怎么办? There are two solutions: 有两种解决方案:

  • The simplest is to delete the branch and recreate it. 最简单的方法是删除分支并重新创建它。 After all, at the point where you did the reintegration merge, you've branch and trunk should have been identical. 毕竟,在进行重新整合的那一点上,分支和主干应该已经完全相同。 In theory, there's nothing wrong with this. 从理论上讲,这没有错。 However, you'll lose your branch's history. 但是,您将失去分支机构的历史记录。

  • The other thing you can do is to make Subversion think that you've merged the change in Revision 101 onto your branch without actually doing the merge. 您可以做的另一件事是让Subversion认为您已经将Revision 101中的更改​​合并到了分支上,而没有实际进行合并。 You could do this by editing svn:mergeinfo yourself, but this can be a bit error prone. 您可以自己编辑svn:mergeinfo来做到这一点,但这可能会出错。

A better way is to use the --record-only option on the merge: 更好的方法是在合并中使用--record-only选项:

$ svn co REPO/branch/1.2
$ cd 1.2
$ svn merge -r101 --record-only $REPO/trunk
$ svn commit -m"Rev 101 was my reintegration merge from 1.2->trunk"

All better. 一切都好。 Now, when I try to do my merge, Subversion will merge Revision 102 on trunk into my branch, but not my reintegration revision. 现在,当我尝试进行合并时,Subversion会将主干上的修订版102合并到我的分支中,而不是我的重新集成修订版中。

In fact, if I did the --record-only merge right after my reintegration merge, I could have done this: 实际上,如果我在重新整合合并之后--record-only--record-only合并,则可以这样做:

$ cd 1.2
$ svn merge --record-only $REPO/trunk

That's because all other revisions -- except for my reintegration merge -- were already on the branch. 那是因为除我的重新整合合并外,所有其他修订都已经在分支机构中。 All I've done is update svn:mergeinfo to include revision 101 from trunk. 我所做的只是更新svn:mergeinfo以包含来自主干的修订版101。

So, for your first mistake , it may be okay. 因此,对于您的第一个错误 ,可能还可以。 Check to see if trunk and your branch agree at that point. 检查中继和您的分支在那时是否同意。 As I said, newer versions of Subversion understand that merging back from branch to trunk should be a reintegration merge -- even if you didn't include the --reintegration parameter. 如我所说,较新版本的Subversion理解从分支合并到主干应该是重新--reintegration合并-即使您没有包括--reintegration参数。 If not, you might have a bit more work to untangle the situation. 如果没有,您可能需要做更多的工作来解决这种情况。

For your second mistake, do a --record-only merge from trunk to branch to update the svn:mergeinfo . 对于第二个错误,请从主干到分支执行--record-only合并以更新svn:mergeinfo If you can't, you might have to munge svn:mergeinfo by hand. 如果不能,则可能必须手动修改svn:mergeinfo It's not all that difficult to do use svn propedit , and you can edit the property in your favorite editor. 使用svn propedit并不难,您可以在自己喜欢的编辑器中编辑属性。 The format of svn:mergeinfo is pretty obvious, so adding in an extra revision isn't that difficult. svn:mergeinfo的格式非常明显,因此添加额外的修订版本并不困难。

Always remember. 总记得。 This is version control. 这是版本控制。 Nothing is permanently damaged. 没有任何东西被永久损坏。 You can always go back to an earlier version of your repository, and try again. 您始终可以返回到存储库的早期版本,然后重试。 The worst thing you get is a record of your blunderous ways permanently etched into svn log . 您得到的最糟糕的是永久记录到svn log中的错误方法的svn log

If that's the worst thing that has ever happened in your life, you have lead a highly blessed existence on this rocky little planet. 如果那是您一生中发生过的最糟糕的事情,那么您已经在这个多岩石的小星球上度过了幸福的时光。

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

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