Manuals / Git & GitHub / Ch 9

C · RecoverAdvanced35 min read

9. git bisect — find the breaking commit

Git & GitHub · 48 pages source format

Binary search through history. Mark good and bad commits. Git checks out middle. O(log n) instead of manual.

What you'll learn

  • git bisect start/good/bad
  • Automated bisect run
  • bisect reset

Manual bisect

git bisect start. git bisect bad (current broken). git bisect good <old-good-hash>. Test. git bisect good/bad until found.

git bisect start
git bisect bad
git bisect good v1.0-tag
# test each checkout
git bisect good   # or bad
git bisect reset   # when done

Do this now

Plant a bug in commit 3 of 8 in practice repo. Bisect to find it.

Clear?

Automated bisect

git bisect run ./test.sh — script exits 0 for good, 1 for bad. Git automates the search.

Do this now

Write test.sh checking for planted bug. bisect run test.sh.

Clear?

When QA uses bisect

Regression found in release? bisect between last good build and bad build narrows the culprit commit.

Do this now

Write when-you-would-bisect note for your team context.

Clear?

Checklist