这很大程度上取决于你指的是“逆转”。
暂时转换到另一个承诺
# This will detach your HEAD, that is, leave you with no branch checked out:
git checkout 0d1d7fc32
git checkout -b old-state 0d1d7fc32
要回到你所在的地方,只需检查你所在的分支再次(如果你做了变化,如往常交换分支时,你将不得不处理它们,你可以重新设置,把它们扔掉;你可以打破,支票,打破,把它们带到你身边;你可以承诺它们到一个分支,如果你想要一个分支在那里。
硬删除未发表的承诺
如果,另一方面,你真的想摆脱你从那时起所做的一切,有两种可能性。
# This will destroy any local modifications.
# Don't do it if you have uncommitted work you want to keep.
git reset --hard 0d1d7fc32
# Alternatively, if there's work to keep:
git stash
git reset --hard 0d1d7fc32
git stash pop
# This saves the modifications, then reapplies that patch after resetting.
# You could get merge conflicts, if you've modified things which were
# changed since the commit you reset to.
如果你混乱,你已经扔掉了你的地方变化,但你至少可以通过重新设置回到你以前的地方。
下一篇: 与新承诺发布的承诺
# This will create three separate revert commits:
git revert a867b4af 25eee4ca 0766c053
# It also takes ranges. This will revert the last two commits:
git revert HEAD~2..HEAD
#Similarly, you can revert a range of commits using commit hashes (non inclusive of first hash):
git revert 0d1d7fc..a867b4a
# Reverting a merge commit
git revert -m 1 <merge_commit_sha>
# To get just one, you could use `rebase -i` to squash them afterwards
# Or, you could do it manually (be sure to do this at top level of the repo)
# get your index and work tree into the desired state, without changing HEAD:
git checkout 0d1d7fc32 .
# Then commit. Be sure and write a good message describing what you just did
git commit
您也可以在此情况下找到这个答案有用:我如何将头转回以前的位置?(解密头) & Undo 承诺