Header

How can I revert a Git repository to a previous commit?

Reverting your repository to an old commit

You may find you're in a situation where you need to revert the repository to a previous commit. This can be done using the following command:

$ git revert 8fd3350cf6

Where 8fd3350cf6 is the old commit you're reverting back to. You'll be prompted to review and add a commit message for the revert, but you can leave the default message as it is:

Revert "Add the correct link to Brie"

This reverts commit 8fd3350cf6fba8bcd4abc7233d4ff6b81dd6ed3c.

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch my_new_branch
# Your branch and 'origin/my_new_branch' have diverged,
# and have 1 and 1 different commits each, respectively.
#   (use "git pull" to merge the remote branch into yours)
#
# Changes to be committed:
#       modified:   index.html
#

Then type ctrl+x, followed by the enter key to save it. You'll then see a confirmation message showing that you've reverted successfully:

[my_new_branch 8655d60] Revert "Add the correct link to Brie"
 1 file changed, 1 insertion(+), 1 deletion(-)