Git根据它恢复一个具有其他提交的提交

假设我们提交了AB ,而B取决于A的修改。 我们想要恢复A ,这会成功吗? 另外,如果由'A'添加的行不再存在,会发生什么情况?


git会报告回复导致冲突。 git status将显示未合并的路径。

您可以像解决其他问题一样解决冲突。


以例子编辑:

$ mkdir foo
$ cd foo
$ git init
$ echo "this is a line in a file" > blah
$ echo "this is a second line in a file" >> blah
$ echo "this is a third line in a file" >> blah
$ git add blah
$ git commit -m "first commit"
# edit the second line in blah
$ git commit -am "second commit"
# remove the second line from blah
$ git commit -am "third commit"
$ git revert HEAD^ #revert the second commit
error: could not revert 4862546... another change
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'
$ git status
# On branch master
# Unmerged paths:
#   (use "git reset HEAD <file>..." to unstage)
#   (use "git add <file>..." to mark resolution)
#
#   both modified:      blah
#
no changes added to commit (use "git add" and/or "git commit -a")

在第一次提交添加文件并且第二次修改该文件的情况下,git status将显示如下内容:

$ git status
# On branch master
# Unmerged paths:
#   (use "git reset HEAD <file>..." to unstage)
#   (use "git add/rm <file>..." as appropriate to mark resolution)
#
#   deleted by them:    blah
#
链接地址: http://www.djcxy.com/p/49795.html

上一篇: Git revert a commit that has some other commit depending on it

下一篇: Revert a specific commit from a merged branch that has already been pushed