Home » Git Bisect When Some Revisions Won’t Build

Git Bisect When Some Revisions Won’t Build

A revision line contains passed, failed and skipped commits inside a narrowing search interval.

Use a third outcome when a Git revision cannot be tested. A compiler failure or missing dependency is not evidence that the behavior under investigation regressed. Return the skip status for those commits, and report the remaining candidate range if the skipped revisions prevent Git from identifying a single first bad commit.

Define the behavior independently of the build

Say an export started omitting its header when a filter matches no rows. Before running bisect, verify a revision where the export includes its header and another where the same fixture reproduces the omission. Write a classifier that checks the file contents after a successful build. A failing build cannot answer the header question.

A repeatable wrapper can build the package, run the fixture, and distinguish a known expected failure from setup errors. Keep the wrapper outside the checkout or otherwise ensure that the candidate cannot accidentally replace its test. The Git worktree guide explains how a separate worktree can isolate this investigation from active changes. Keep generated files and unrelated work out of the classifier's inputs.

Use the documented exit contract

git-bisect documentation describes three results for running a test in bisect. Exit zero marks a good revision. A nonzero status in the documented bad range, except 125, marks a bad revision. Exit 125 skips an untestable revision. Ensure your test wrapper translates a missing executable, fixture setup failure or unsupported toolchain into the intended action. Passing an unexamined exit status through can make Git classify an environment error as a defect.

An illustrative shape is:

git bisect start BAD GOOD
git bisect run /absolute/path/check-empty-export.sh
git bisect log
git bisect reset

Use verified commits in place of BAD and GOOD. Preserve the log before resetting. If a build fails precisely because of the regression you are investigating, it might be a valid bad outcome. Define that case before automation.

Two possible first bad commits

We built a disposable three-commit history for the empty-export case and ran Git 2.54.0 against it. The input is an export with zero rows. A successful export still prints the CSV header id,total. The classifier reads the schema from the checkout, runs the exporter and checks stdout. It skips a revision only for the known missing schema. An unexpected execution failure stops the investigation.

Commit   Fixture observation                          Classifier exit
A        Empty export contains id,total                0 (good)
B        Schema file absent; no export to compare      125 (skip)
C        Export runs and stdout is empty               1 (bad)

We supplied C and A as the verified bad and good endpoints, then ran the classifier through git bisect run. Git skipped B. Its final output listed the following candidates (hashes shortened here):

The first bad commit could be any of:
266f0e2  B
00aecb6  C

The classifier returned 125 on B. The overall bisect command exited with 2 in this run and its log recorded B as skipped. C is a proven bad endpoint. Naming it as the first bad commit would go beyond the evidence. Recover B’s original schema, if possible, and test that same empty export. A header on B leaves C as the first bad commit in this history. An empty export on B moves the boundary back to B.

This history is linear and the endpoint results repeat. In a project with a fix followed by a reintroduction, choose endpoints around the introduction you mean to locate. Keep setup changes in the record so a workaround that changes export behavior can be spotted.

Leave a reproducible result

Report the tested good and bad endpoints, skipped revisions and why they could not be tested, test command and observed behavior. Include the bisect log and a suspect interval when that is all the evidence supports. The useful result may be a short set of changes the maintainer can inspect, even when the build history does not support a single answer.

You may also like