【问题标题】:Git revert a commit that has some other commit depending on itGit 还原一个有其他提交的提交
【发布时间】:2013-07-31 12:57:58
【问题描述】:

假设我们有提交AB,而B 依赖于A 的修改。 我们想恢复A,会成功吗?另外,如果'A'添加的行不再存在会怎样?

【问题讨论】:

标签: linux git bash


【解决方案1】:

git 将报告还原导致冲突。 git status 将显示未合并的路径。

你可以像其他人一样resolve the conflict


用例子编辑:

$ 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
#
猜你喜欢
  • 2016-11-01
  • 2011-12-19
  • 2022-10-20
  • 2021-11-02
  • 2021-12-26
相关资源
最近更新 更多