これは、「元に戻す」の意味に大きく依存します。
一時的に別のコミットに切り替えます
一時的にそこに戻りたい場合は、だましてから現在の場所に戻ってください。必要なのは、目的のコミットを確認することだけです。
# This will detach your HEAD, that is, leave you with no branch checked out:
git checkout 0d1d7fc32
または、そこにいる間にコミットしたい場合は、先に進んで、そこにいる間に新しいブランチを作成します。
git checkout -b old-state 0d1d7fc32
元の場所に戻るには、もう一度行っていたブランチを確認してください。(ブランチを切り替えるときはいつものように、変更を加えた場合は、必要に応じて対処する必要があります。リセットして破棄することも、スタッシュ、チェックアウト、スタッシュポップして持ち運ぶこともできます。コミットすることもできます。そこにブランチが必要な場合は、そこにブランチします。)
未公開のコミットをハード削除する
一方、それ以降に行ったすべてのことを本当に取り除きたい場合は、2つの可能性があります。1つは、これらのコミットをまだ公開していない場合は、リセットするだけです。
# 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.
混乱した場合は、ローカルの変更をすでに破棄していますが、少なくとも再度リセットすることで、以前の状態に戻すことができます。
公開されたコミットを新しいコミットで元に戻す
一方、作品を公開した場合は、履歴を効果的に書き換えるため、ブランチをリセットしたくないでしょう。その場合、実際にコミットを元に戻すことができます。Gitの場合、元に戻すには非常に具体的な意味があります。逆パッチを使用してコミットを作成し、それをキャンセルします。このようにして、履歴を書き換えることはありません。
# 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
git-revert
マンページは、実際にはその説明でこれの多くをカバーしています。もう1つの便利なリンクは、git-revertについて説明しているこのgit-scm.comセクションです。
結局元に戻したくないと判断した場合は、元に戻すか(ここで説明)、元に戻す前にリセットすることができます(前のセクションを参照)。
この場合、この回答が役立つこともあります
。HEADを前の場所に戻すにはどうすればよいですか。(切り離された頭)&元にコミットコミット