Goal: pinpoint the exact commit that caused a regression.
Use for:
- a bug that appeared somewhere in a range of commits
- regressions with a clear good and bad state
- narrowing blame when the diff is large
Workflow:
- Find a known-good and a known-bad commit.
- Start bisect: mark bad, then mark good.
- Test the checkout git selects at each step.
- Mark each as good or bad to halve the range.
- Let bisect converge on the first bad commit.
- Reset bisect and inspect that commit's diff.
Automate:
- write a script that exits 0 (good) or non-zero (bad)
- run git bisect run to search hands-free
- ensure the test reliably reproduces the bug
Rules:
- use a reliable, fast reproducer for each step
- keep the working tree clean between steps
- run git bisect reset when finished
- a flaky test makes bisect lie; stabilize it first