Undo Git Pull

This tutorial demonstrates undoing a git pull to bring a git repository to a previous state using git hard reset.

Undo Git Pull

To undo a git pull with the hard reset, we use the git reset --hard command and specify the HEAD.

Let us see the commits that we have made on our git repository by using the git log command with --oneline and --graph options as shown below.

git log

We have made three commits to the repository, and the most recent commit is the * bdb9fc2.

To undo the recent commit using hard reset, we use the git reset command with the --hard option, as shown below. The HEAD^ specifies that return to the commit before HEAD.

first_git_reset

The output of the git log command shows that we have returned to the previous commit.

As shown below, we can also use HEAD~1 to specify to return to the commit before HEAD. HEAD~2 means a return to two commits before HEAD.

second_git_reset

Write for us
DelftStack articles are written by software geeks like you. If you also would like to contribute to DelftStack by writing paid articles, you can check the write for us page.

Related Article - Git Pull

  • Overwrite Local Changes in Git
  • Difference Between Git Fetch and Git Pull
  • Pull Changes From a Specific Branch in Git
  • Pull Changes From Another Branch in Git
  • Related Article - Gt Undo

  • Overwrite Local Changes in Git
  • Difference Between Git Fetch and Git Pull
  • Pull Changes From a Specific Branch in Git
  • Pull Changes From Another Branch in Git