Automate Git Bisect and Skip Untestable Revisions
Make the test stable
A bisect runner should test the same behavior at every revision. Keep a trusted test script outside the changing checkout, so old revisions cannot replace it. The supplied check-note.sh reads the synthetic notes.txt only; it does not execute historical code. For real projects use an isolated runner, no production secrets, pinned dependencies and a reproducible environment. Test the script on both endpoints before automation.
Use an explicit exit status contract
For git bisect run, 0 means good; 1–127 except 125 means bad; 125 skips the revision; other statuses stop the run. A missing command (127) can be misclassified as bad, so validate the runner itself. In this example the script returns 1 only for the exact known regression, and 125 for missing or unexpected content. The path ../check-note.sh belongs to the manual fixture.
#!/bin/sh[ -f notes.txt ] || exit 125value=$(cat notes.txt) || exit 125case "$value" in "Water every 3 days") exit 0 ;; "Water every 3") exit 1 ;; *) exit 125 ;;esacAutomate the decisions
Run the external script through sh, explicitly inspect the result and save the log if useful. On the nine-commit fixture the automated run finds c5 and leaves the branch tip unchanged. It is not necessary to guess a midpoint: Git selects candidates. Use bisect reset after the result, even if the run stopped early.
git bisect start c8 c0git bisect run sh ../check-note.shgit bisect loggit bisect resetSkipping may leave uncertainty
The second fixture has good c0, untestable c1 and bad c2. If c1 cannot be checked, both c1 and c2 can be candidates; do not claim a unique culprit. git bisect skip can be used manually, or 125 in an automated run. Improve the test environment or inspect the two patches to narrow further. Save evidence before cleanup. Practice: classify a missing notes.txt, a known bad note and a correct note with the exit status contract.
git bisect start c2 c0git bisect skipgit bisect loggit bisect resetCheck Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Automate Git Bisect and Skip Untestable Revisions — knowledge check
Reason about regression and historical evidence.
Which run exit code is good?
Which code requests skip?
Why is 127 dangerous in a runner?
Why keep a trusted script outside the checkout?
What if the only intermediate revision is skipped?