Sub topic 11
Using custom terms instead of good and bad
This chapter assumes you have run a manual bisect session and know the exit code contract: 0 means old, 1 to 127 (except 125) means new, 125 means skip.
Why "good" and "bad" can mislead
By default, git bisect calls the older state "good" and the newer state "bad". That fits a hunt for a regression. It fits poorly when you want to find the commit that fixed a bug, or the commit that changed any other property, such as a performance change or a renamed option.
In a fix hunt, the old commits are the broken ones and the new commits are the fixed ones. Typing git bisect good for a commit that still has the bug is easy to get wrong. Custom terms let you name the two states so the commands read correctly.
Naming the two states
Pass --term-old and --term-new when you start the session. The old term names the state that holds at the start of the range. The new term names the state that appears at some commit and stays after it.
git bisect start --term-old=broken --term-new=fixed
git bisect broken v1.4.0
git bisect fixed mainGit now accepts git bisect broken and git bisect fixed in place of good and bad. It reports the search in your words. The final line reads "first fixed commit" instead of "first bad commit".
You can also use the generic names old and new. They work in any session, so git bisect old and git bisect new are always valid. To see the terms of the current session, run git bisect terms.
The older options --term-good and --term-bad still work as aliases for --term-old and --term-new. Use the old and new forms in new scripts.
The exit codes still follow old and new
Custom terms change the vocabulary only. The contract between your script and Git stays the same:
| Script exit status | State Git records | In the fix hunt above |
|---|---|---|
| 0 | old | broken |
| 1 to 124, 126, 127 | new | fixed |
| 125 | skip | untestable |
| 128 or higher | abort | stop the run |
Exit 0 means "old", whatever you named it. In a regression hunt, 0 means "the bug is absent". In a fix hunt, the old state is the broken one, so 0 must mean "the bug is still present". Your script's logic has to be inverted.
#!/bin/sh
# find-fix.sh: exit 0 = still broken (old), 1 = fixed (new), 125 = cannot test
make >/dev/null 2>&1 || exit 125
if ./run_regression_test.sh; then
exit 1 # the test passes, so the bug is gone
else
exit 0 # the test fails, so the bug is still present
fiRun it the same way as before:
git bisect run ./find-fix.shGit prints the first fixed commit at the end. As in earlier chapters, keep the script outside the checked-out files so the checkout does not replace it.
Check the direction before you search
Inverting the exit codes is the most common mistake with custom terms. A script written for a regression hunt gives the opposite answer here. Git then converges on a commit that looks plausible but is wrong, because bisect assumes the old state comes first and the new state stays after it.
Run the validation step from the earlier chapter before you start:
git checkout v1.4.0 && ./find-fix.sh; echo "old endpoint exit: $?"
git checkout main && ./find-fix.sh; echo "new endpoint exit: $?"The old endpoint must print 0 and the new endpoint must print a code from 1 to 127.
Ending the session
Custom terms last only for the current session. git bisect reset ends it and returns you to your original branch. If you save the session with git bisect log, the log records the terms, so git bisect replay restores them along with the steps.
Exercise
You want the commit that fixed a crash. v2.0.0 crashes and main does not. You start with git bisect start --term-old=crashes --term-new=stable. What exit code should your script return for a commit where the crash still happens, and what does a crash-free commit return?
Show answer
A commit where the crash still happens is in the old state, so the script returns 0. A crash-free commit is in the new state, so it returns a code from 1 to 127 other than 125, such as 1. A commit that cannot be built returns 125 so Git skips it.