advanced

git bisect

Binary-search commit history with a reproducible test to isolate the first bad change quickly.

`git bisect` binary-searches history to find the first bad commit. You need a **deterministic** classifier: a test, script, or build step that returns good vs bad.

					git bisect start
git bisect bad                  # current HEAD is bad
git bisect good v2.3.0          # known good tag
# Git checks out middle commit — run test, then:
git bisect good   # or git bisect bad
git bisect run npm test -- --grep="regression"
git bisect reset
				

Skip unbuildable commits with `git bisect skip`. Automate with `bisect run` when the test is reliable.

On interviews: flaky tests invalidating bisect, first bad commit vs root cause, automating classification.

Common pitfalls: flaky tests flip good/bad; first bad commit may only expose a latent bug; not validating the suspect manually after bisect ends.

The trade-off is bisect speed (log₂ n steps) versus setup cost of a reliable reproducer.

Checklist:

  • Stabilize reproduction before bisect.
  • Automate with `bisect run` when possible.
  • Skip commits that cannot build.
  • Validate the final suspect with focused analysis.