Backlog uses cookies to deliver our services. By visiting our website, you agree to the use of cookies as described in our Cookie Policy.

For this tutorial step, we have prepared a repository with some ready made commits to speed things up.

You can download the repository here.

In this step, we are going to undo the previous two commits using the reset command.

Go to the downloaded "stepup-tutorial/tutorial3" directory and examine the history of this repository. It should look like the following.

Current history

Let's confirm the branch's history using the log command.

$ git log commit 0d4a808c26908cd5fe4b6294a00150342d1a58be Author: yourname <yourname@yourmail.com> Date: Mon Jul 16 23:19:26 2012 +0900 append description of the pull command commit 9a54fd4dd22dbe22dd966581bc78e83f16cee1d7 Author: yourname <yourname@yourmail.com> Date: Mon Jul 16 23:19:01 2012 +0900 append description of the commit command commit 326fc9f70d022afdd31b0072dbbae003783d77ed Author: yourname <yourname@yourmail.com> Date: Mon Jul 16 23:17:56 2012 +0900 append description of the add command commit 48eec1ddf73a7fb508ef664efd6b3d873631742f Author: yourname <yourname@yourmail.com> Date: Mon Jul 16 23:16:14 2012 +0900 first commit

Open sample.txt and verify that the text content looks something like below.

Git commands even a monkey can understand add: Register a change in an index commit: Save the status of an index pull: Obtain the content of the remote repository

Use the reset command to delete the previous two commits like below.

Delete the commit
$ git reset --hard HEAD~~ HEAD is now at 326fc9f append description of the add command

If done correctly, sample.txt should no longer contain the last two lines "commit: Save the status of an index" and "pull: Obtain the content of the remote repository". You can also verify that these commits are no longer in the history with the log command.

$ git log commit 326fc9f70d022afdd31b0072dbbae003783d77ed Author: yourname <yourname@yourmail.com> Date: Mon Jul 16 23:17:56 2012 +0900 append description of the add command commit 48eec1ddf73a7fb508ef664efd6b3d873631742f Author: yourname <yourname@yourmail.com> Date: Mon Jul 16 23:16:14 2012 +0900 first commit

ORIG_HEAD points to the original commit before reset actually takes place. This may come in handy especially when you accidentally issue a reset. You can restore the previous history by executing a reset to ORIG_HEAD.

$ git reset --hard ORIG_HEAD HEAD is now at 0d4a808 append description of the pull command