# 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 stashgit reset --hard 0d1d7fc32git 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.& z! z- z- o9 u; L' F
如果你搞砸了,你已经扔掉了当地的变化,但至少你可以通过重置回到以前的位置。/ |1 |& p* Y8 E8 x
使用新提交撤销已发布的提交另一方面,如果你已经发表了作品,你可能不想重置分支,因为它实际上是在重写历史。在这种情况下,您确实可以恢复提交。Git,revert 有一个非常特殊的含义:使用反向补丁创建并提交以取消它。这样你就不会重写任何历史了。 6 f! }+ b5 z. L4 h
# 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 commitgit revert -m 1 # 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 didgit commit: ]2 Y8 I9 I/ D% k/ G( l% q