Sub topic 8
Skipping commits that cannot be tested with 125
This chapter assumes you can write a short shell script, run your project's build from the command line, and have already used git bisect run with a script that returns 0 or 1.
Why some commits cannot be judged
A bisect session asks one question per commit: does the bug appear here? Sometimes the question has no answer. A commit in the middle of your range may not compile, or a dependency it needs may be missing. A test harness may not exist yet at that point in history.
If your script returns 1 for these commits, Git records them as bad. That corrupts the search. Git then reports a first bad commit that only broke the build, and the real regression is hidden behind it.
Exit code 125 solves this. It tells Git "I could not test this commit, so do not count it as good or bad." Git then picks a nearby commit and carries on.
The exit codes again
| Exit code | Meaning to `git bisect run` |
|---|---|
| 0 | Good: the bug is not present |
| 1 to 124, 126, 127 | Bad: the bug is present |
| 125 | Skip: this commit cannot be tested |
| 128 and above | Abort: stop the whole bisect |
Because 126 and 127 mean bad, a script that fails with "command not found" (127) is treated as finding the bug. Test your tooling before the search starts, as described in the endpoint-validation chapter.
A script that separates build failures from bug failures
The key rule is to separate "I could not run the test" from "the test ran and failed."
#!/bin/sh
# check.sh: exit 0 = good, 1 = bad, 125 = cannot test this commit
make >/dev/null 2>&1 || exit 125
./run_regression_test.shThe first line builds the project. If the build fails, the script exits with 125 and Git skips the commit. If the build succeeds, the last line runs the regression test. The shell returns that test's exit status, so 0 means good and a non-zero code means bad.
For a one-off search you can pass the check inline:
git bisect run sh -c 'make || exit 125; ./run_regression_test.sh'What Git does after a skip
When a commit is skipped, Git tests a different commit close to the midpoint. The search continues, and the range still shrinks.
Skipping has a cost. If the commits next to the culprit are all untestable, Git cannot separate them. It then reports a set of possible first bad commits instead of one. You will see a message that the first bad commit could be any of a list. You then inspect those commits by hand.
Common errors
- Skipping too much. A script that returns 125 for any failure, including test failures, never finds anything. Use 125 only for failures of the build or setup.
- Letting the build fail silently. If you drop
|| exit 125, a broken build usually returns non-zero and counts as bad. - A broken test harness. If
run_regression_test.shitself is missing at some commits, it exits 127. Git reads that as bad. Check for the file first and exit 125 if it is absent. - Dirty build output. Stale files from a previous build can make a broken commit look fine. Run a clean step before building if your build cache is unreliable.
You can also skip by hand during a manual session with git bisect skip. The 125 code is the automated form of that command.
Exercise
Your script runs make and then the regression test. At a commit in the middle of the range, make fails with a compiler error. What should the script return for that commit, and what happens if it returns 1 instead?
Show answer
It should return 125, so Git skips the commit. If it returns 1, Git marks the commit as bad. Git may then report the commit where the build broke as the first bad commit, even though the regression came from a different commit.