Recover and debug Git history safely

8 steps · about 3 h 40 min · Intermediate

  1. Establish repository state (reference, Git documentation, 20 min)

    Separate working-tree, index and history changes before attempting recovery.

  2. Inspect project history (reference, Git documentation, 30 min)

    Filter commits by path, author, date or message to narrow the investigation.

  3. Compare exact changes (reference, Git documentation, 30 min)

    See differences between the working tree, index, commits and branches.

  4. Trace a line's context (reference, Git documentation, 25 min)

    Find the commit that last changed a line, then read that commit rather than assigning blame blindly.

  5. Locate the first bad commit (reference, Git documentation, 35 min)

    Use binary search and a reproducible check to isolate a regression efficiently.

  6. Restore selected files (reference, Git documentation, 25 min)

    Recover working-tree or index content while stating the source explicitly.

  7. Undo a published change (reference, Git documentation, 25 min)

    Create a new inverse commit without rewriting shared history.

  8. Recover a displaced commit (reference, Git documentation, 30 min)

    Use local reference history to find work that is no longer named by a branch.