Sub topic 9
Reading the result and inspecting the first bad commit
This chapter assumes you can already run git bisect run with a working reproducer script, as covered in the earlier chapters. It covers what happens after the search stops: how to read Git's final report, how to check that the commit it names is the real cause, and how to leave the repository in a clean state.
What Git prints when the search ends
git bisect run prints one block per step. Each block shows the script being run, how many revisions remain, and the commit now checked out. When the range has narrowed to a single commit, Git prints a final report.
running './check.sh'
Bisecting: 0 revisions left to test after this (roughly 0 steps)
[3f9c2e1b7a5d4c8e0b6f1a2d9c4e7b3a5f8d0c1e] Simplify header parsing
running './check.sh'
3f9c2e1b7a5d4c8e0b6f1a2d9c4e7b3a5f8d0c1e is the first bad commit
commit 3f9c2e1b7a5d4c8e0b6f1a2d9c4e7b3a5f8d0c1e
Author: Dana Lee <[email protected]>
Date: Tue Nov 10 14:02:11 2026 +0000
Simplify header parsing
src/parser.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
bisect found first bad commitThe report has three parts:
- The verdict line.
<sha> is the first bad commitnames the commit. It is the earliest commit in your range for which the script exited with a "bad" code, given that everything before it behaved as good. - The commit summary. Git shows the author, date, message, and a diffstat, so you often recognize the change at once.
- The closing line. The wording varies by Git version. Older versions print
bisect run success, and newer ones printbisect found first bad commit. Both mean the search finished. Neither means your script was correct.
Your working tree is still in the middle of the session. HEAD is detached at the last commit Git tested, which is not necessarily the first bad commit. Git checks out the candidate it wants to test next, and the last test may have been on a good commit. Do not start editing or committing here.
The result is only as good as the script
Bisect assumes the history is clean: every commit before the first bad one is good, and every commit from it onward is bad. The script defines what "good" and "bad" mean. If it reports a wrong answer even once, the search is steered the wrong way, and Git still prints a confident verdict at the end.
Common ways to get a wrong result:
| Cause | Symptom |
|---|---|
| The script fails for a different reason than the bug (missing dependency, build error returned as 1) | The first bad commit is the one that broke the build, not the one that introduced the regression |
| The failure is intermittent | The verdict lands on a random commit and changes between runs |
| The good endpoint was not actually good | Git reports the oldest commit in range, or an unrelated one |
| Skipped commits surround the culprit | Git cannot name one commit and lists several candidates |
Treat the verdict as a hypothesis. The next sections show how to test it.
Inspecting the commit
Start with what Git already told you, then look deeper.
git show --stat 3f9c2e1--stat lists the files changed. A small, focused change in an area related to the bug is a good sign. A commit that touches hundreds of files, such as a formatting sweep, a dependency upgrade, or a rename, deserves suspicion. It may be the cause, but the useful change is hidden inside it.
To read the full diff:
git show 3f9c2e1To see only one file's changes:
git show 3f9c2e1 -- src/parser.cTo see the commit's relationship to its neighbors, view the history around it:
git log --oneline --graph -n 10 3f9c2e1If the commit message links an issue or pull request, read that too. It often explains the intent of the change, which tells you whether the bug is a mistake in the commit or a case the author did not know about.
Narrowing down within the commit
When the diff is large, you can bisect within it. Check out the parent, apply parts of the change, and rerun the script. A quicker approach is to revert one file at a time on a scratch branch.
git checkout -b bisect-scratch 3f9c2e1
git checkout 3f9c2e1^ -- src/parser.c
./check.sh; echo "exit: $?"If the script now passes, the change to src/parser.c is the cause. If it still fails, restore that file and try another one. This works well for commits that combine several changes.
Confirm the verdict by hand
Before filing a report or writing a fix, run your script on the commit and on its parent. This check takes about a minute and catches most wrong verdicts.
git checkout 3f9c2e1^
./check.sh; echo "parent exit: $?"
git checkout 3f9c2e1
./check.sh; echo "culprit exit: $?"You should see 0 for the parent and a bad code (1 to 127, except 125) for the culprit. If both print 0, the failure is not deterministic, or the script's result depends on something other than the checked-out files, such as a stale build directory or cached data. If both are bad, the real culprit is earlier than the range suggests, so check your good endpoint again.
Run the pair a second time. A deterministic regression gives the same answers every time.
The diagram below summarizes the decision after a verdict.
When Git cannot name one commit
If too many commits were skipped with exit code 125, Git may stop with a list instead of a single commit:
There are only 'skip'ped commits left to test.
The first bad commit could be any of:
8a1d0c4e7b3a5f8d0c1e3f9c2e1b7a5d4c8e0b6f
b2d9c4e7b3a5f8d0c1e3f9c2e1b7a5d4c8e0b6f1
We cannot bisect more!This is a correct result. The bug was introduced somewhere in that group, and the script could not tell where because none of those commits could be tested. Your options are:
- Read the listed commits and decide which is most likely, using
git showon each. - Make the commits testable. For example, a build failure that affects only a few commits may be fixable with a small patch applied by the script before it builds.
- Accept the group as the answer and report all of them.
Finding where else the commit went
Once you trust the culprit, you usually need to know which releases are affected.
git tag --contains 3f9c2e1
git branch --contains 3f9c2e1
git describe --contains 3f9c2e1git tag --contains lists tags whose history includes the commit. git branch --contains does the same for local branches, and -r adds remote branches. git describe --contains names the commit relative to the nearest tag that follows it, such as v1.5.0~12.
To learn who else touched the same lines, use git blame with the parent as the starting point so the culprit does not hide earlier history:
git blame -L 40,60 3f9c2e1^ -- src/parser.cTo find every commit that added or removed a given string, use the pickaxe search:
git log -S"parse_header" --oneline -- src/parser.cSaving the evidence, then cleaning up
The session is still active until you reset it. Save the log first, because the log is what lets you or a colleague replay the search later.
git bisect log > bisect.log
git bisect resetgit bisect reset returns you to the branch or commit you were on when you ran git bisect start, and removes the bisect state from the repository. If you want to end up somewhere else, pass a commit:
git bisect reset mainA reproducible record is worth attaching to a bug report: the bisect.log file, the script, and the commit hash. Anyone can then run git bisect replay bisect.log and arrive at the same checkout.
If you forget to reset, nothing is lost, but later commands behave oddly because HEAD is detached and Git still considers a bisect in progress. Running git bisect log shows whether a session is active. It fails with an error if none is.
Acting on the result
After inspecting and confirming the commit, the usual choices are:
- Revert it with
git revert 3f9c2e1, when the change is not needed or the fix is not yet known. This is the safest option on a shared branch, because it adds a new commit rather than rewriting history. - Fix forward, when the commit contains useful work and the bug is a small oversight. Add a regression test that your bisect script could have used.
- Report it to the author with the hash, the script, and the log.
Keep the script. Turning it into a permanent test means the same regression is caught earlier next time.
Exercise
git bisect run ends with "<sha> is the first bad commit". You check out the parent of that commit and run your script, and it exits with 1. What does this tell you, and what should you do next?
Show answer
The parent also fails, so the named commit is not the first bad one. Either the good endpoint was not actually good, or the script gave a wrong answer during the search (for example by failing for a reason unrelated to the bug, or intermittently). Fix the script or choose a verified good commit, confirm the script passes there, and restart the bisect.
Exercise
A bisect ends with "The first bad commit could be any of:" followed by three hashes. Why did Git not name a single commit, and what are two ways to proceed?
Show answer
Those three commits were skipped (exit code 125) because the script could not test them, so Git cannot tell which of them introduced the bug. You can read each commit's diff and judge which is most likely, or make the commits testable (for example by patching the build problem in the script) and rerun the bisect so each one gets a real verdict.