Fixing mistakes with the reset command
At any stage during development, you might want to undo an operation, fix mistakes, or abandon your current work. There is no git undo
command in core Git, and neither is there support for the universal --undo
option in Git commands, though many commands have an --abort
option to abandon current work in progress (WIP). 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 any situation, which is not limited to the provided example usage.
Note that this section only covers the full-tree mode of git reset
; the description of what git reset -- <file>
does, which is an alternative to using the more modern git restore <file>
command, has been left for the...