Git: Revert to previous commit status

I’m confused. I want to go back to a previous commit that I identified in “git log”.

But when I do “git checkout “, I don’t get said commit. Nothing changes.
It tells me I’m in detached HEAD mode, but the files I want are not there.

  • Why all my Xcode commits to Bitbucket show other user 'Author Name' on Bitbucket?
  • Git-commit unable to open vim
  • Have .gitignore to NOT ignore an .htaccess file within top level directory
  • Commit to multiple branches at the same time with git
  • git: change one line in file for the complete history
  • Why did the changes of a git commit disappear after other 2 commits (where I did not change the affected file)?
  • What the eff am I doing wrong?


  • what is the meaning and difference PVCS version - SVN revision - GIT sha value
  • Setting up sbt to publish to artifactory based on git branch
  • GitBlit Cant find Repositories after Jboss Restart
  • 403 error when pushing to GitHub
  • Git merge only the final result of a development branch
  • Azure external GIT deployment wont ask for credentials
  • 2 Solutions collect form web for “Git: Revert to previous commit status”

    git reset --hard <commit> From the manpage:

    Matches the working tree and index to that of the tree being switched to. Any changes to tracked files in the working tree since are lost.

    git checkout is for switching your working directory to a different branch or commit. This does not move the HEAD there.

    DO NOT git reset -hard it is PERMANENT!

    Please use

    git stash -u 

    instead! If you have a piece of work in there that you zapped by accident, you can still get it back. This never gets pushed to your remote unless you choose to do so by making a branch out of it and pushing it up.

    Also, you are on the right track that you can use git checkout to accomplish the same thing. The syntax is

    git checkout HEAD -- . 

    But it has the same problem as git reset --hard. Stick with stash and you will save losing your hair in the future.

    Longer answer

    The above solutions revert all your changes. However, you asked how to get rid of some of the changes. I’ll add this for completeness.

    To do this, you can

    git add file1 file2 file3
    git stash save --patch

    You will now be prompted for what exactly you want to make dissappear… down to what ever level of granularity. So you can safely “reject” only a few changes to a single file if you choose to do so.

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