Undo and Recovery
Everyone makes mistakes in Git, including people who have used it for a decade. The difference is that they know which mistakes are reversible, which is nearly all of them, and which are not, which is a short and memorable list.
This section is the one to read before you need it. It starts with the safety net, gives you a map from "what I did wrong" to "the command that fixes it", then works through each fix in detail. By the end, the sentence "I think I broke something" stops being frightening.
Before you start: Section 5 for the everyday commands and Section 6 for branches. The decision guide at the end is the page to bookmark.
Lessons in this section
- The safety net and the reflog
- The undo map
- restore vs reset vs revert vs rebase
- git reset: soft, mixed, hard
- Recover files, branches, commits; detached HEAD
- Recover from a failed merge or rebase
- Wrong branch: committed or pushed to the wrong place
- Force push
- The dangerous commands list
- Decision guide: which undo do I need?