How to revert an unnecessary “git reset HEAD~1”

After running git reset HEAD~1, I noticed that actually there was nothing else to do and the commit was fine. Is there a way to revert this command?

  • Create a git tree from working tree without touching the index?
  • How can I find out what files have changed in the post-checkout hook in git?
  • How to do interactive rebase with Intellij IDEA?
  • Are their names the same: a local-tracking branch, the corresponding remote-tracking branch, and the corresponding remote branch being tracked?
  • How do I do the reverse of gitk's “Write commit to file”?
  • Possible to ask “git mergetool” to automatically keep trying other files even if merging one file fails?
  • migrating existing project to git
  • How do I interactively unstage a particular hunk in git?
  • How to find the git object id of an object with a known hash
  • Is there a way to see all changed files on a branch in Git?
  • git log since yesterday for working days only
  • Tell git to ignore my RSA public key
  • 3 Solutions collect form web for “How to revert an unnecessary “git reset HEAD~1””

    You can use:

    git reset HEAD@{1}
    

    This uses the last entry in the reflog. See git reflog if you did other things in between.

    You could see the commit id of that commit with git reflog.

    Even easier (if you haven’t done any other operations):

    git reset ORIG_HEAD
    

    ORIG_HEAD is the previous state of HEAD.

    More details about HEAD vs. ORIG_HEAD are in the answer to this SO question.

    Git Baby is a git and github fan, let's start git clone.