恢复“放弃所有更改”合并效果

发布于 2024-11-04 11:55:23 字数 726 浏览 7 评论 0原文

让我们假设它是通过“放弃合并中的所有更改...”选项执行合并的,但是意外。

并且这个错误的提交已经被提交到“中央”存储库中。

如果我需要以正确的方式合并分支更改,如何处理这种情况?

重现案例的命令:

hg init mr
cd mr

echo "123" > file.txt
hg add
hg ci -m "initial"

hg branch br
echo "234" >> file.txt
hg ci -m "in branch"

hg up default
echo "567" >> file.txt
hg ci -m "in default"

在这些命令之后打开 tortoisehg,并将第二个修订版(默认头)与带有“Discard ...”选项的 br 分支合并。

UPD

这是一个关于做相反的事情如何使用 Mercurial 命令行合并以摆脱头部,就像我可以使用 TortoiseHg 那样? ;-)

但仍然不能找到如何恢复该步骤:-(

Let's suppose it was performed merge with "Discard all changes from merge ..." option, bu accident.

And this wrong commit has been committed into the "central" repository.

How to deal with this case if I need to merge in correct way the branch changes?

Commands to reproduce the case:

hg init mr
cd mr

echo "123" > file.txt
hg add
hg ci -m "initial"

hg branch br
echo "234" >> file.txt
hg ci -m "in branch"

hg up default
echo "567" >> file.txt
hg ci -m "in default"

After these commands open tortoisehg, and merge 2nd revision (default head) with br branch with "Discard ..." option.

UPD:

It is a question about doing the opposite How to merge to get rid of head with Mercurial command line, like I can do with TortoiseHg? ;-)

But still cannot find how to revert that step :-(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏日落 2024-11-11 11:55:23

一种方法是重做合并,然后再进行一次合并并丢弃。

在您的示例中,更新回第二个修订版(执行错误合并之前的当前工作目录父目录),然后与其他分支重做合并。这次一定要好好做。

这会给你另一个头。

然后,与旧的、不正确的合并合并,并选择丢弃。现在您已经用正确的合并有效地绕过了这一合并。

如果您不确定这些步骤,请进行本地克隆并进行实验,您始终可以放弃它并重新克隆并重试。

修订版 3 是旧的、不正确的合并,我在其中选择了丢弃。执行合并 4 和 5 后,该合并的痕迹就消失了,一切都恢复正常。是的,历史看起来有点奇怪,但是相信我,完全消除不良合并的清理程序比历史时间线上的小问题要糟糕得多。

基本上,在失败的合并之后,您会遇到这种情况:

            +-- botched merge
            v
    0---2---3
     \     /
      1---+

因此,您更新回错误合并之前的工作文件夹父级,并进行另一次合并,这次是正确的。现在看起来像这样:

            +-- botched merge
            v
    0---2---3
     \   \ /
      \   x
       1-+-4
           ^
           +-- good merge

您的工作文件夹现在处于修订版 4,因此您进行了另一次合并,这次是修订版 3(错误的合并),并选择放弃这些更改,然后您将得到以下结果:

            +-- botched merge
            v
    0---2---3-5  <-- final merge, discard 3
     \   \ / /
      \   x /
       1-+-4
           ^
           +-- good merge

以下是 TortoiseHg 的显示方式:

新合并后的历史

One way would be to redo the merge, and do yet another merge with discard.

In your example, update back to the 2nd revision (the current working directory parent before you did the bad merge), then redo the merge with that other branch. Do it properly this time.

This will give you another head.

Then, merge with the old, incorrect merge, and choose discard on this. Now you have effectively bypassed this merge with a correct one.

If you're unsure about the steps, make a local clone and experiment, you can always just discard it and reclone and try again.

Revision 3 is the old, incorrect merge, where I chose discard. After doing merge 4 and 5, the traces of that merge is gone and everything is back in working order. Yes, the history looks a little funky, but trust me, the cleanup procedures to get rid of that bad merge completely is far worse than the little hickup on your history timeline.

Basically you have this scenario after the botched merge:

            +-- botched merge
            v
    0---2---3
     \     /
      1---+

So you update back to the working folder parent you had before the bad merge, and do another merge, this time properly. Now it looks like this:

            +-- botched merge
            v
    0---2---3
     \   \ /
      \   x
       1-+-4
           ^
           +-- good merge

Your working folder is now at revision 4, so you do yet another merge, this time with revision 3 (the bad merge), and choose to discard those changes, and you get this:

            +-- botched merge
            v
    0---2---3-5  <-- final merge, discard 3
     \   \ / /
      \   x /
       1-+-4
           ^
           +-- good merge

Here's how TortoiseHg shows this:

history after new merges

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文