Undo – remove a commit completely
In this example, we'll learn how we can undo a commit as if it had never happened. We'll learn how we can use the reset
command to effectively discard the commit and thereby reset our branch to the desired state.
Getting ready
In this example, we'll use the example of the hello world
repository, clone the repository, and change your working directory to the cloned one:
$ git clone https://github.com/dvaske/hello_world_cookbook.git $ cd hello_world_cookbook
How to do it...
First, we'll try to undo the latest commit in the repository as though it never happened:
We'll make sure our working directory is clean, no files are in the modified state, and nothing is added to the index:
$ git status On branch master Your branch is up-to-date with 'origin/master'. nothing to commit, working directory clean
Also, check what is in our working tree:
$ ls HelloWorld.java Makefile hello_world.c
If all works well, we'll check the log to see the history of the repository...