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.
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
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 status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
- Also...