How do you roll back (reset) a Git repository to a particular commit?

This question already has an answer here:

  • How to revert Git repository to a previous commit?

    33 answers

  • Difference between git checkout --track origin/branch and git checkout -b branch origin/branch
  • GIT post-receive hook doesn't run
  • git not installed in Program Files
  • git smudge/clean filter between branches
  • git autocrlf input does convert line-endings but from LF to CRLF?
  • Cannot checkout, file is unmerged
  • Git pull and specify directory?
  • Default config settings for a new git repository?
  • Safe git rebase
  • How to tag an older commit in Git?
  • cygwin git thinks that file previously had different mode
  • Remove all deleted files from “changed but not updated” in Git
  • 4 Solutions collect form web for “How do you roll back (reset) a Git repository to a particular commit?”

    git reset --hard <tag/branch/commit id>


    • git reset without the --hard option resets the commit history, but not the files. With the --hard option the files in working tree are also reset. (credited user)

    • If you wish to commit that state so that the remote repository also points to the rolled back commit do: git push <reponame> -f (credited user)


    Because of changes to how tracking branches are created and pushed I no longer recommend renaming branches. This is what I recommend now:

    Make a copy of the branch at its current state:

    git branch crazyexperiment

    (The git branch <name> command will leave you with your current branch still checked out.)

    Reset your current branch to your desired commit with git reset:

    git reset --hard c2e7af2b51

    (Replace c2e7af2b51 with the commit that you want to go back to.)

    When you decide that your crazy experiment branch doesn’t contain anything useful, you can delete it with:

    git branch -D crazyexperiment

    It’s always nice when you’re starting out with history-modifying git commands (reset, rebase) to create backup branches before you run them. Eventually once you’re comfortable you won’t find it necessary. If you do modify your history in a way that you don’t want and haven’t created a backup branch, look into git reflog. Git keeps commits around for quite a while even if there are no branches or tags pointing to them.

    Original answer:

    A slightly less scary way to do this than the git reset --hard method is to create a new branch. Let’s assume that you’re on the master branch and the commit you want to go back to is c2e7af2b51.

    Rename your current master branch:

    git branch -m crazyexperiment

    Check out your good commit:

    git checkout c2e7af2b51

    Make your new master branch here:

    git checkout -b master

    Now you still have your crazy experiment around if you want to look at it later, but your master branch is back at your last known good point, ready to be added to. If you really want to throw away your experiment, you can use:

    git branch -D crazyexperiment

    For those with a git gui bent, you can also use gitk.

    Right click on the commit you want to return to and select “Reset master branch to here”. Then choose hard from the next menu.

    When you say the ‘GUI Tool’, I assume you’re using Git For Windows.

    IMPORTANT, I would highly recommend creating a new branch to do this on if you haven’t already. That way your master can remain the same while you test out your changes.

    With the GUI you need to ‘roll back this commit’ like you have with the history on the right of your view. Then you will notice you have all the unwanted files as changes to commit on the left.
    Now you need to right click on the grey title above all the uncommited files and select ‘disregard changes’. This will set your files back to how they were in this version.

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