gpt4 book ai didi

git - 为什么在这种特殊情况下 git revert 后会发生冲突

转载 作者:行者123 更新时间:2023-12-05 06:36:46 30 4
gpt4 key购买 nike

我有一个一开始看起来像这样的文件

asd
bnm
cvb

然后我添加了三个提交:

1.

asd feature1 c1
bnm
cvb

2.

asd feature1 c1
bnm feature1 c2
cvb

3.

asd feature1 c1
bnm feature1 c2
cvb feature1 c3

现在当我想恢复第二个提交时

git revert HEAD^

我收到这样的错误消息

error: could not revert 2222222... feature 1 commit 2
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'

我的文件看起来像这样

<<<<<<< HEAD
bnm feature1 c2
cvb feature1 c3
=======
bnm
cvb
\>>>>>>> parent of 2222222... feature 1 commit 2

我只是不明白为什么。我的假设是它会像 Edwar Thomson 在他对这个问题的回答中解释的那样工作: git revert: Why do I get conflicts?我没有两次编辑第 2 行,应该不会发生冲突。我错过了什么?

我希望结果是

asd feature1 c1
bnm
cvb feature1 c3

没有任何冲突。

最佳答案

这里缺少的是恢复,就像 cherry-pick 一样,只是应用补丁(这里是过去提交的负面形象)。
它不是 merge 。

这意味着,正如我在“Git cherry-pick causes merge conflict while merging does not”中所描述的,它没有共同祖先的概念。

问题是由 git revert 计算的补丁的上下文:请参阅“Conflicts from apply and stash”。

还原(2 和 1 之间的负差异)尝试取消第 2 行(将 bnm feature1 c2 还原为 bnm第三行之前HEAD 内容上的 cvb) 行 not cvb 作为第三行。
应用该补丁时,Git 不知道如何处理第三行:应该保留它,还是将其修改为 cvb

参见“Why does this cherry-pick have a conflict?”中的另一个示例。

关于git - 为什么在这种特殊情况下 git revert 后会发生冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48839104/

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