首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >我对git还原是如何工作的感到困惑。

我对git还原是如何工作的感到困惑。
EN

Stack Overflow用户
提问于 2019-04-10 00:10:24
回答 2查看 402关注 0票数 2

我想知道是怎么回事。我创建了一个HTML文件并在其中放了一些行

代码语言:javascript
运行
AI代码解释
复制
this is first line
this is second line
this is third line
this is fourth line

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

现在,我执行了提交c的还原,但是它引发了一个错误:

代码语言:javascript
运行
AI代码解释
复制
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-还原是如何工作的。我知道类似于“撤消提交并添加新提交”,但不知道如何成功地使用它。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-04-10 00:19:42

它创建了要还原的提交的反向修补程序,因此在您的示例中,提交c如下所示:

代码语言:javascript
运行
AI代码解释
复制
 this is first line
 this is second line
+this is third line
# End of file

然后,在d中运行git revert c,因此它尝试创建以下内容并将其应用于树:

代码语言:javascript
运行
AI代码解释
复制
 this is first line
 this is second line
-this is third line
# End of file

但是,您的文件如下所示:

代码语言:javascript
运行
AI代码解释
复制
this is first line
this is second line
this is third line
this is fourth line
# End of file

因此,创建的修补程序不适用(文件结束与第四行冲突)。所以当吉特告诉你:

代码语言:javascript
运行
AI代码解释
复制
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'

意思是“我试着做你要求的,但我面临一个我无法解决的案子”,所以你需要:

很可能,你的决议是:

代码语言:javascript
运行
AI代码解释
复制
this is first line
this is second line
this is fourth line
票数 4
EN

Stack Overflow用户

发布于 2019-04-10 00:35:55

git命令可以被认为是“撤销”类型的命令,但是它不是传统的撤消操作。

本质上,它取消在指定提交中完成的所有操作,然后在流程中创建一个新提交。您可以查看以获得更多信息。

关于你的问题,你会遇到合并冲突。为了解决这些冲突,您可以使用(Ex )。(美联)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55607712

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档