How it works...

Effectively, we are just changing the pointer of the master branch to point to the previous commit HEAD, which means the first parent of HEAD. Now, the branch will point to 9c7532f, instead of the commit we removed, 35b29ae. This is shown in the following diagram:

The preceding diagram also shows that the original 3061dc6 commit is still present in the repository, but new commits on the master branch will start from 9c7532f; the 3061dc6 commit is called a dangling commit.

You should only perform this undo operation on commits you haven't shared (pushed) yet, since when you create new commits following undo or reset, those commits ...

Get Git Version Control Cookbook 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.