gpt4 book ai didi

git - 我对 git revert 的工作原理感到困惑

转载 作者:太空狗 更新时间:2023-10-29 14:35:13 25 4
gpt4 key购买 nike

我想知道发生了什么。我创建了一个 HTML 文件并在其中放了一些行

this is first line
this is second line
this is third line
this is fourth line

并在每一行之后分别提交,例如提交 a、提交 b、提交 c、提交 d。

现在我执行了一个恢复到提交 c,但是它抛出了一个错误:

could not revert 82b69e5... c

hint: after resolving the conflicts, mark the corrected paths <br>
hint: with 'git add <paths>' or 'git rm <paths>' <br>
hint: and commit the result with 'git commit'<br>

我想知道 git-revert 是如何工作的。我知道类似“撤消提交并添加新提交”的东西,但不知道如何成功使用它。

最佳答案

它为您要还原的提交创建了一个反向补丁,因此在您的情况下,提交 c 看起来像:

 this is first line
this is second line
+this is third line
# End of file

然后,从 d 运行 git revert c,它会尝试创建以下内容并将其应用到您的树上:

 this is first line
this is second line
-this is third line
# End of file

但是,您的文件看起来像:

this is first line
this is second line
this is third line
this is fourth line
# End of file

因此创建的补丁不适用(文件末尾与第四行冲突)。所以当 Git 告诉你:

could not revert 82b69e5... c
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add ' or 'git rm '
hint: and commit the result with 'git commit'

它的意思是“我试着按照你的要求去做,但我遇到了一个我无法解决的案例”,所以你需要:

您的解决方案很可能是:

this is first line
this is second line
this is fourth line

关于git - 我对 git revert 的工作原理感到困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55607712/

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