在 Git 中重新进行恢复合并 [英] Re-doing a reverted merge in Git

查看:132
本文介绍了在 Git 中重新进行恢复合并的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里遇到了一个小问题:我在 Git 中有一个特定于问题的分支 28s,我将它合并到了通用的 develop 分支中.事实证明我做得太快了,所以我使用 git-revert 来撤消合并.然而,现在已经到了将28s合并到develop中的时候了,但是git-merge命令看到了原来的合并,高兴地宣布一切顺利,分支已经存在合并.现在我该怎么做?创建一个'RevertRevert"28s -> develop"'提交?似乎不是一个好方法,但我目前无法想象其他任何方法.

树状结构的样子:

解决方案

您必须还原还原".根据您原始版本的还原方式,它可能不像听起来那么容易.查看官方文档主题.

---o---o---o---M---x---x---W---x---Y/- -A B C D

允许:

---o---o---o---M---x---x-------x-------*//- -A B C D

<块引用>

但这一切都有效吗?当然可以.您可以恢复合并,并从纯技术角度,git做的很自然,没有真正的麻烦.
它只是认为它从合并前的状态"到合并后的状态",就是这样.
没有什么复杂的,没有什么奇怪的,没有什么真正危险的.Git 会不假思索地去做.

所以从技术角度来看,恢复合并没有错,但从工作流程的角度来看,您通常应该尝试这样做避免.

如果可能的话,例如,如果你发现一个被合并的问题进入主树,与其恢复合并,不如真的努力:

  • 将问题分成你合并的分支,然后修复它,
  • 或者尝试恢复导致它的单个提交.

是的,它更复杂,不,它并不总是有效(有时答案是:哎呀,我真的不应该合并它,因为它不是准备好了,我真的需要撤消所有合并").那么你确实应该恢复合并,但是当您想重新进行合并时,您现在需要通过还原还原来完成.

I have run into a bit of a problem here: I had a problem-specific branch 28s in Git, that I merged in the general develop branch. Turns out I had done it too fast, so I used git-revert to undo the merge. Now, however, the time has come to merge 28s into develop, but git-merge command sees the original merge, and happily announces that all is well and branches have been already merged. What do I do now? Create a 'Revert "Revert "28s -> develop"" ' commit? Doesn't seem to be a good way to do it, but I can't imagine any other at the moment.

What the tree structure looks like:

解决方案

You have to "revert the revert". Depending on you how did the original revert, it may not be as easy as it sounds. Look at the official document on this topic.

---o---o---o---M---x---x---W---x---Y
              /
      ---A---B-------------------C---D

to allow:

---o---o---o---M---x---x-------x-------*
              /                       /
      ---A---B-------------------C---D

But does it all work? Sure it does. You can revert a merge, and from a purely technical angle, git did it very naturally and had no real troubles.
It just considered it a change from "state before merge" to "state after merge", and that was it.
Nothing complicated, nothing odd, nothing really dangerous. Git will do it without even thinking about it.

So from a technical angle, there's nothing wrong with reverting a merge, but from a workflow angle it's something that you generally should try to avoid.

If at all possible, for example, if you find a problem that got merged into the main tree, rather than revert the merge, try really hard to:

  • bisect the problem down into the branch you merged, and just fix it,
  • or try to revert the individual commit that caused it.

Yes, it's more complex, and no, it's not always going to work (sometimes the answer is: "oops, I really shouldn't have merged it, because it wasn't ready yet, and I really need to undo all of the merge"). So then you really should revert the merge, but when you want to re-do the merge, you now need to do it by reverting the revert.

这篇关于在 Git 中重新进行恢复合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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