Git revert a commit that has some other commit dep

2019-08-15 03:25发布

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?

标签: linux git bash
1条回答
smile是对你的礼貌
2楼-- · 2019-08-15 03:47

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
#
查看更多
登录 后发表回答