Mercurial-撤消旧合并 [英] Mercurial - backout an old merge

查看:51
本文介绍了Mercurial-撤消旧合并的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个看起来像这样的分支:

I have a branch that looks like this:

A->B->C->D->...->Z
     ^
1->2-^

其中C2及其祖先的合并.

where C is a merge from 2 and its ancestors.

我现在意识到我不应该合并.我可以回到B并移植D ... Z,但这是很多工作.我可以退出C吗?

I realize now that I should not have merged. I could go back to B and graft D...Z but that's a lot of work. Can I backout JUST C?

当我尝试hg backout --merge C时,我得到 abort:无法撤消合并变更集.

这些更改已推送到中央仓库,我不想修改历史记录或其他任何内容,我只想要2的反义词,并且它的祖先是B的共同后代.

These changes have been pushed to the central repo and I'm not looking to modify history or anything, I just want the inverse of 2 and it's ancestors back to the common descendant with B.

推荐答案

合并是公共的,并且此合并中有公共的提交

假设我们有此发布的提交历史记录(顶部是最新的):

Merge is public and there are public commits on this merge

Assume we have this published history of commits (top is the newest):

                  revZ
                   |
                  ...  
                   |
                  revD
                   |
                  revC     <- unwated merge commit (rev2 to revB)
                   |   \    
wanted branch ->  revB  rev2    <- unwanted branch
                   |     |

相反,我们希望处于最高状态,就好像我们拥有以下历史记录一样:

Instead, we would like to have top state as if we had this history:

                  revZ'
                   |
                  ...  
                   |
                  revD'
                   |       
wanted branch ->  revB  rev2    <- unwanted branch
                   |     |

如何做到(逐步)

  1. 合并合并提交(revD-revZ)为一次提交后的历史记录

  1. Callapse the history after merge commit (revD - revZ) into one commit

$ hg update -r revC                # Update to merge commit
$ hg revert --all -r revZ          # revert to the newest commit
$ hg commit -m "collapsed commits" # Create new commit (revTmp1)

                   revZ
                    |  
                   ...
                    |  
           revTmp1 revD
                 \ /
                 revC
                  |  \    
                revB  rev2
                  |    |

  • 将合并(revTmp1)后的更改复制到所需分支(revB)

  • Copy changes after merge (revTmp1) to wanted branch (revB)

    $ hg update -r revB    # Update to the last "wanted" commit before merge
    $ hg graft -r revTmp1  # Copy changes from revTmp1 (create revTmp2 commit)
    
                       revZ
                        |  
                       ...
                        |  
               revTmp1 revD
                     \ /
            revTmp2  revC
                  \  / \    
                 revB  rev2
                   |     |
    

  • 创建退出"提交

  • Create a "backout" commit

    $ hg update -r revZ                   # Update to the top commit
    $ hg revert --all -r revTmp2          # Copy state revTmp2
    $ hg commit -m "reverted revC merge"  # Create revZ' commit
    
                       revZ'
                        |
                       revZ
                        |  
                       ...
                        |  
               revTmp1 revD
                     \ /
            revTmp2  revC
                  \  / \    
                  revB  rev2
                   |     |
    

  • 清理临时提交

  • Clean the temporary commits

    $ hg strip revTmp1 revTmp2
    
                      revZ'          <- reverted revC merge
                       |  
                      revZ
                       |  
                      revD
                       |
                      revC     <- unwated merge commit (rev2 to revB)
                       |   \    
    wanted branch ->  revB  rev2    <- unwanted branch
                       |     |
    

  • 这篇关于Mercurial-撤消旧合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆