Git revert a commit that has some other commit depending on it
Let's say we have commit A
and B
, and B
depends on A
's modification. We want to revert A
, will that be successful? Also, what would happen if a line added by 'A' is no longer present?
git
will report that the revert resulted in a conflict. git status
will show the unmerged paths.
You can resolve the conflict like any other.
Edit with example:
$ 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")
In the case that the first commit added the file and the second modified that file, git status will show this:
$ 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/49796.html
上一篇: Git:恢复单个文件的旧提交
下一篇: Git根据它恢复一个具有其他提交的提交