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 ...
Get Git: Mastering Version Control now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.