git - 我对 git revert 的工作方式感到困惑
问题描述
我想知道发生了什么事。我创建了一个 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'
它的意思是“我试图按照你的要求去做,但我遇到了一个我无法解决的案子”,所以你需要:
- 解决冲突,使用如何解决 Git 中的合并冲突
- 或取消还原
git revert --quit
最有可能的是,您的解决方案是:
this is first line
this is second line
this is fourth line
推荐阅读
- python - Python线程似乎被冻结了
- c++ - 如何将大量数据作为值存储在 std::map 中?
- jquery - 无法在 onbeforeunload 事件上建立 ajax 连接
- python - 如何使用 python 过滤值,例如使用 grep
- dart - 就应用程序性能而言,代码风格真的很重要吗?
- sql - 查找并消除逻辑重复
- xml - 如何获取与父元素属性 (xslt) 不匹配的最后一个子元素属性?
- c# - 令牌到期时为 200 - 对吗?
- codec - 使用 dash.js 播放 PlayReady 4.0+ 测试内容
- javascript - 显示由可拖动 div 悬停的标签内容