gpt4 book ai didi

Git:如何在不覆盖历史记录的情况下恢复分支 merge ?

转载 作者:IT王子 更新时间:2023-10-29 01:27:28 24 4
gpt4 key购买 nike

我有两个分支:masteropengl。我最近完成了(或者至少我是这么认为的)opengl 分支,并决定将其 merge 到 master 中:

git checkout master
git merge opengl
git push

在我这样做之后,几个在 master 分支上工作的开发人员取消了我的更改,结果发现我的实现与他们的一些代码冲突。因此,我想恢复 master 分支上的 merge 操作,但不覆盖历史记录。

请注意,我希望最终能够将 opengl 分支 merge 到 master 中(在我修复所有错误之后)。因此,简单地检查旧版本的 master 并提交它是行不通的 - 当我尝试 merge 它时,新创建的提交将取消我对 opengl 的更改。

谢谢。

最佳答案

How to revert a faulty merge 提到的文档“cebewee ”解释了为什么 git revert 在恢复 merge 时很棘手。

So the merge will still exist, and it will still be seen as joining the two branches together, and future merges will see that merge as the last shared state - and the revert that reverted the merge brought in will not affect that at all.
If you think of "revert" as "undo", then you're going to always miss this part of reverts.
Yes, it undoes the data, but no, it doesn't undo history.

git revert 在这里是正确的解决方案,但它会在将来再次 merge 该分支时产生影响。
那么接下来的merge就得先“revert the revert”,再merge branch。

关于Git:如何在不覆盖历史记录的情况下恢复分支 merge ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5383659/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com