Skip to content
rajin

29Debugging history with bisect and blame

advanced25–30 minHandbook pp. 63–64 Not started

Warm-up · from “Reflog, fsck and disaster recovery”

Why is reflog local?

No notes: write what you remember, then check. Recalling before reading is what makes it stick.

The problem

A test used to pass, but after twenty commits it fails. How can you find the first bad commit without reading every change?

After this lesson you can

  • Use bisect to isolate a regression.

  • Interpret blame as evidence.

  • Inspect a suspected commit.

Key terms

Full glossary

Say what each term means, then open it to check.

  • Commit · from lesson 7

    Object identifying a root tree, parent(s), metadata and message.

Visual mental model

  1. Known good A
  2. midpoint test
  3. narrower range
  4. first bad candidate

Build the mental model

Git bisect searches between a known good and bad commit by checking intermediate commits and asking you to classify them. In a simple linear history with a stable reproducible failure, binary search reduces the number of tests. Use git bisect start, git bisect bad and git bisect good GOOD_ID; test each checkout and label it. git bisect run can automate a test whose exit status reliably indicates good or bad. Use git bisect reset when done.

SimulationBinary search for the first bad commit

A simplified model for building intuition. It does not read your sandbox; use the terminal for real behaviour.

Under the hood

Git blame attributes lines to commits in a selected revision, which helps locate relevant changes. It does not prove who caused a bug or who owns the code. Renames, moves and formatting may affect attribution; inspect git show and surrounding history. Bisect is most useful when the test is deterministic and works on historical revisions; skip untestable commits when needed.

Common mistake · important nuance

Do not use blame as a people-management metric. Treat both tools as evidence for debugging.

Move between parts freely. Completion counts only what you verify and answer.