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 Git-Version-Control-Cookbook-Second-Edition_hello_world_cookbook
repository, clone the repository, and change our working directory to the cloned one:
$ git clone https://github.com/PacktPublishing/Git-Version-Control-Cookbook-Second-
Edition_hello_world_cookbook.git $ cd Git-Version-Control-Cookbook-Second-Edition_hello_world_cookbook.git
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 that our working directory is clean, no files are in the modified state, and nothing is added to the index:
$ git statusOn branch masterYour branch is up-to-date with 'origin/master'.nothing to commit, working directory clean
- Also, check...