Theory

Updated

October 30, 2026

Theory: Bisect is Binary Search on First-Parent History

If a test can label a commit good or bad, git bisect finds the first bad commit in O(log N) checkouts.

Invariants

  1. You mark an old good and a current bad; Git checks out the midpoint.
  2. git bisect run ./test.sh automates the oracle.
  3. Skip unbuildable commits; they are not evidence.
  4. The answer is a commit hash, not a file.
G G G G B B B B    (good/bad along a chain)
      ^ first bad

What can break

  • A flaky test (non-monotonic good/bad).
  • Bisecting a merge-heavy history without understanding first-parent.

How to read this chapter

Manual bisect, automate with tests, 2 AM story, lab.