Fixing mistakes with the reset command

At any stage during development, you might want to undo something, to fix mistakes, or to abandon the current work. There is no git undo command in core Git, and neither is there support for the --undo option in Git commands, though many commands have an --abort option to abandon current work in progress. One of the reasons why there is no such command or option yet is the ambiguity on what needs to be undone (especially for multi-step operations).

Many mistakes can be fixed with the help of the git reset command. It can be used for various purposes and in various ways; understanding how this command works will help you in using it in many situation, not limited to provided example usage.

Note that this section ...

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.