本文介绍了如何在Mercurial中退出合并,然后再与该分支重新合并?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个分支,默认分支和branch1.错误地,我们团队中的一个人默认合并了branch1. branch1中的内容尚未准备好与默认值合并(它包含对构建和部署环境的重大修改).

I have two branches, default and branch1. By mistake one person in our team merged branch1 with default. The content in branch1 is not yet ready to merge with default (it contains a major rework of the build & deploy environment).

我们使用"hg backout"进行了实验,并退出了合并(不确定这样做是否正确).然后,默认情况下会删除来自branch1的更改,这很好-但是我们无法与branch1重新合并.

We did an experiment with 'hg backout', backing out the merge (not sure this is the right way to do it). Then the changes from branch1 gets deleted on default, which is fine - but we can not remerge with branch1.

我们应该如何解决这个问题?

How should we solve this issue?

推荐答案

在这里可能需要执行许多方案,我将每个方案作为标题,以便您可以找到适合自己情况的方案. .请注意,我仍在学习Mercurial,如果我说的话有误,使用错误的术语,可以做得更好等,我希望得到一些指示.

There are many scenarios here where you might want to do this, I'll make each scenario a headline, so that you can find the scenario that fits your case. Note that I'm still learning Mercurial, and I'd like pointers if something I say is wrong, using the wrong terminology, could be done better, etc.

程序员已经合并,但没有做任何其他事情,也没有以任何方式与任何人共享更改

在这种情况下,只需丢弃本地克隆,然后从安全的存储库中获取新的克隆.

In this case, simply discard the local clone, and get a fresh clone from a safe repository.

程序员已合并,并根据该合并继续工作.合并后的变更集应保留,但合并本身应删除.更改(合并+以下更改集)尚未与任何人共享

在这种情况下,我将执行以下四个操作之一:

In this case I would do one of four:

  1. 尝试使用REBASE扩展名,这会将更改集从一个位置移动到另一位置.如果变更集基于合并中引入的代码变更,则必须执行一些手动工作来调和差异.
  2. 尝试使用MQ扩展将要保存的变更集放入补丁队列中,然后将其推回到其他位置.但是,就基于合并的更改而言,这将与REBASE扩展存在相同的问题
  3. 尝试使用TRANSPLANT扩展名将更改从一个位置复制"到另一位置.尽管如此,仍然存在与前两个​​相同的问题.
  4. 可能需要借助差异化工具来再次进行工作,以对要丢弃的变更集进行更改,然后在正确的位置重新进行.

要摆脱合并变更集和以下所有变更集,有几个选项:

To get rid of the merge changeset + all the following changesets, there's a couple of options:

  1. 在MQ扩展中使用strip命令

  1. Use the strip command in the MQ extension

hg strip <hash of merge changeset>

  • 克隆并提取,并指定导致但不包括合并的变更集的哈希值.本质上,通过将损坏的克隆拉入新克隆来创建新克隆,并避免引入不需要的合并.

  • Clone and pull, and specify the hash of the changesets leading up to, but not including the merge. In essence, create a new clone by pulling from the damaged clone into a new one, and avoid pulling in the merge you don't want.

    hg clone damaged -r <hash of first parent> .
    hg pull damaged -r <hash of second parent>
    

  • 合并推向他人,控制克隆

    程序员已推送到主存储库,或推到其他人,或从程序员存储库拉出的某人.但是,您(在开发人员组中)拥有对所有存储库的控制权,例如,您可以在完成更多工作之前与所有人联系并进行交谈

    在这种情况下,我将看是否可以执行步骤1或2,但是可能必须在很多地方完成,所以这可能涉及很多工作.

    In this case, I would see if step 1 or 2 could be done, but it might have to be done in a lot of places, so this might involve a lot of work.

    如果没有人根据合并变更集完成工作,我将使用步骤1或2进行清理,然后推送到主存储库,并要求每个人从主存储库中获取新的克隆.

    If nobody has done work based on the merge changeset, I would use step 1 or 2 to clean up, then push to the master repository, and ask everyone to get a fresh clone from the master repository.

    程序员推送了合并集,您不知道谁将拥有合并变更集.换句话说,如果您成功地从您的存储库中删除了它,那么仍然拥有它的人的漫不经心的推动将把它带回来.

    The programmer pushed the mergeset, and you don't know who will have the merge changeset. In other words, if you succeed in eradicating it from your repositories, a stray push from someone who still has it will bring it back.

    忽略合并变更集,并像从未发生过一样在两个分支中工作.这将留下一个悬挂的头.然后,您可以在合并两个分支后,对该头进行空合并以摆脱它.

    Ignore the merge changeset and work in the two branches as though it never happened. This will leave a dangling head. You can then later, when you've merged the two branches, do a null-merge for this head to get rid of it.

      M         <-- this is the one you want to disregard
     / \
    *   *
    |   |
    *   *
    |   |
    

    只需继续在两个分支中工作:

    Simply continue working in the two branches:

    |   |
    *   *
    | M |       <-- this is the one you want to disregard
    |/ \|
    *   *
    |   |
    *   *
    |   |
    

    然后,您将两者合并,即您想要的真正合并:

    Then later you merge the two, the real merge you want:

      m
     / \
    *   *
    |   |
    *   *
    | M |       <-- this is the one you want to disregard
    |/ \|
    *   *
    |   |
    *   *
    |   |
    

    然后可以进行空合并以摆脱悬垂的头部.不幸的是,除了通过TortoiseHg,我不知道该怎么做.它有一个复选框,我可以在其中丢弃分支之一中的更改.

    You can then do a null-merge to get rid of the dangling head. Unfortunately I don't know how to do that except through TortoiseHg. It has a checkbox where I can discard the changes from one of the branches.

    使用TortoiseHg,我将更新到要保留的合并(最上面的小写字母m),然后选择并右键单击下面悬空的合并头,然后选中丢弃所有来自合并目标的更改(其他) 修订":

    With TortoiseHg, I would update to the merge I want to keep (the topmost, lowercase m), then select and right-click on the dangling merge head below, and then check the "Discard all changes from merge target (other) revision":

    这篇关于如何在Mercurial中退出合并,然后再与该分支重新合并?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    09-04 20:09