Git Course 0%

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

  1. The safety net and the reflogIntermediate≈ 10 min
  2. The undo mapIntermediate≈ 12 min
  3. restore vs reset vs revert vs rebaseIntermediate≈ 12 min
  4. git reset: soft, mixed, hardAdvanced≈ 12 min
  5. Recover files, branches, commits; detached HEADAdvanced≈ 14 min
  6. Recover from a failed merge or rebaseAdvanced≈ 9 min
  7. Wrong branch: committed or pushed to the wrong placeAdvanced≈ 10 min
  8. Force pushAdvanced≈ 9 min
  9. The dangerous commands listAdvanced≈ 8 min
  10. Decision guide: which undo do I need?Intermediate≈ 5 min