Sub topic 8
Skipping commits that cannot be tested with 125
This chapter assumes you can run git bisect run with a script and that you know the exit code contract: 0 means good, 1 to 127 (except 125) means bad. It covers the code that falls outside the good/bad split: 125, which tells Git "I can't judge this commit."
Why some commits cannot be tested
A bisect assumes that every commit it checks out gives a clear answer. Real histories often break that assumption. Typical cases:
- The commit does not compile, for example because a header was renamed in one commit and its users were fixed in the next.
- A dependency is missing or a lockfile is inconsistent at that point in history.
- A different, unrelated bug stops the test from reaching the code you care about.
- A test fixture or database migration the test needs does not exist yet.
If your script reports these commits as bad, Git moves toward them and can end on the wrong commit. A broken build that fails with exit code 2 counts as "the regression is present." Bisect then blames the commit that broke the build, not the one that introduced your bug.
If your script reports them as good, the same error happens in the other direction.
Exit code 125 avoids both mistakes. It tells Git that this commit is neither good nor bad and should be excluded from the search.
What Git does when it receives 125
When git bisect run sees 125, it runs git bisect skip for the current commit. The commit is marked as untestable. Git then chooses a different commit from the remaining candidates, close to the midpoint it wanted, and tests that one instead.
Each skip costs you part of the efficiency of the binary search. The search still converges, but it may need a few more steps.
The exit code table, with the range that matters here highlighted:
| Exit code | Meaning to Git | Effect |
|---|---|---|
| 0 | Good (old) | Search continues in the newer half |
| 1 to 124, 126, 127 | Bad (new) | Search continues in the older half |
| 125 | Cannot test | Commit is skipped, Git picks a nearby one |
| 128 to 255 | Fatal | The whole `git bisect run` stops |
The standard pattern: build failure is a skip
The most common use is to report a failed build as 125 and to let the test decide everything else. This is the script from the earlier chapters:
#!/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 || ensures that make failing ends the script with 125 right away. If make succeeds, the script's final command runs, and its exit status becomes the script's exit status. Run it in the usual way:
git bisect start HEAD v1.4.0
git bisect run ./check.sh
git bisect resetIf you don't need a separate file, put the same logic inline:
git bisect run sh -c 'make || exit 125; ./run_regression_test.sh'Being precise: skip only the right failures
The build-failure pattern is convenient, but it is a blunt tool. Two problems come up often.
First, a failed build may itself be the regression. If you are hunting "the project no longer compiles on this platform," then a failing make is the bad answer. Mapping it to 125 would hide the very commit you want.
Second, a test that fails for any reason returns non-zero, so every unrelated failure looks like your regression. A better script checks for the specific symptom and skips everything else:
#!/bin/sh
# check.sh: look for one specific symptom, skip anything else odd
make >/dev/null 2>&1 || exit 125
out=$(./app --export report.csv 2>&1)
status=$?
if [ "$status" -eq 0 ]; then
exit 0
fi
case "$out" in
*"unexpected column count"*) exit 1 ;;
*) exit 125 ;;
esacThis script gives three answers:
- The export works: good.
- The export fails with the known error message: bad.
- The export fails in some other way: untestable.
The last branch protects you from blaming a commit for a different bug that happened to exist in the same range.
Pitfalls with exit codes
Several details of the contract produce surprising results.
- Codes of 128 and above abort the run. Tools killed by a signal often produce these. A segfault in a shell reports 139. If your test program can crash and you want that counted as bad, wrap it:
./test_app || exit 1. - Negative values wrap.
exit(-1)in C leaves a status of 255, which aborts the run. - A missing command gives 127. If the script calls a tool that is not installed, the shell exits with 127, which Git reads as bad. Every commit then looks bad. This is another reason to check the script on the endpoints first.
- The last command decides. In a shell script without
set -e, the script's status is that of the last command. A cleanup step such asrm -f out.tmpat the end can overwrite the test result with 0. Save the status in a variable and exit with it.
A script that cleans up and keeps the status:
#!/bin/sh
make >/dev/null 2>&1 || exit 125
./run_regression_test.sh
status=$?
rm -f out.tmp
exit "$status"Build artifacts and skipped commits
A failed build can leave partial files behind. The next commit then builds against stale objects and may pass or fail for the wrong reason. Three habits help:
- Build out of tree when the project supports it, so a clean checkout starts from a clean build directory.
- Run a clean step in the script before the build, for example
make cleanorgit clean -fdx -e check.sh. Be careful withgit clean, because it deletes untracked files, including your script if it lives inside the repository. - Keep the script outside the working tree, as covered earlier, and call it by absolute path.
Skipping by hand
You can also skip commits yourself during a manual session:
git bisect skipThis skips the current commit. You can give a commit or a range, which is useful when you know a whole stretch of history does not build:
git bisect skip v2.5..v2.6A range skip is valid only while the range is a known problem. If the first bad commit lies inside it, Git cannot find it, as the next section shows.
When skipping leaves no answer
Git can only name a first bad commit if it has tested the commit right before it and the commit itself. If the commits around the boundary were all skipped, Git cannot tell which of them introduced the bug. Instead of a single answer, it lists candidates:
There are only 'skip'ped commits left to test.
The first bad commit could be any of:
3f1a9c2e7d...
b84d05a1c9...
e2c7710f33...
We cannot bisect more!This is not an error in your script. It means the history between the last good and the first bad commit contains commits that cannot be tested. What you can do:
- Inspect the candidates with
git showorgit log -p. Often the bug is clear from the diffs. - Make the broken commits testable. Apply a small fix to the build locally, for example with
git cherry-pickof a later repair commit, as part of the script, so the commit builds. - Narrow the search. Start a new bisect between the last good commit and the first candidate.
Checking how many commits were skipped
Review what happened with the session log:
git bisect logSkipped commits appear as git bisect skip lines. A few skips are normal. A log full of skips means the script is misclassifying commits, or the range is badly broken, and it is worth checking the script before trusting the result.
Summary
- Exit 125 marks a commit untestable, and Git picks a nearby commit instead.
- Use it for build failures and other problems unrelated to the bug, but not when the failure is the bug.
- Test for the specific symptom, and send anything unexpected to 125.
- Codes of 128 and above abort the run, and the final command in the script sets its exit status.
- If every commit around the boundary is skipped, Git reports a list of candidates instead of one commit.
Exercise
Your reproducer script runs make, then ./app --check. A commit in the middle of the range fails to compile because of an unrelated typo that the next commit fixes. The script has no special handling and make exits with status 2. What does git bisect run conclude about that commit, and how do you change the script?
Show answer
Git treats status 2 as bad, because it is in the 1 to 127 range and is not 125. The search then moves toward older commits and may end on the wrong commit. Change the script to make >/dev/null 2>&1 || exit 125 before running ./app --check, so the broken commit is skipped.
Exercise
A bisect finishes with "There are only 'skip'ped commits left to test" and lists three candidates. Name two things you can do to find the real first bad commit.
Show answer
Inspect the three candidate commits with git show or git log -p and look for the change that causes the bug. Alternatively, make the candidates testable, for example by applying the later repair commit temporarily in the script, and then run the bisect again between the last good commit and the first candidate.