Sub topic 9
Reading the result and inspecting the first bad commit
This chapter assumes you can run git bisect run with a working check script and are comfortable reading git log and git show. Here you learn what the final output means, how to inspect the commit Git names, and how to confirm the answer before you act on it.
What the output looks like
When the search ends, Git prints a line naming the first bad commit, followed by that commit's details. A typical run ends like this:
3f9c2a1d8b7e4f6a5c0d1e2f3a4b5c6d7e8f9a0b is the first bad commit
commit 3f9c2a1d8b7e4f6a5c0d1e2f3a4b5c6d7e8f9a0b
Author: Dana Ortiz <[email protected]>
Date: Tue Nov 17 10:12:44 2026 +0000
Cache parsed config between requests
src/config.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
bisect found first bad commitThe hash on the first line is the answer. Every commit in your range before it passed your script, and this commit and everything after it failed. The "first bad commit" is the earliest commit where the script's result changed from good to bad.
Git also prints progress lines during the search, such as Bisecting: 3 revisions left to test after this (roughly 2 steps). Those are estimates and do not need to match your own count exactly.
Inspect the commit
Git has already left you in a detached HEAD state on a commit near the culprit. Do not start editing here. Use read-only commands first.
git show 3f9c2a1
git show --stat 3f9c2a1
git log -1 --format='%H%n%an%n%ad%n%s' 3f9c2a1
git diff 3f9c2a1^ 3f9c2a1 -- src/config.cgit show prints the message and the full diff. --stat gives a quick list of touched files. The ^ suffix means "the parent of this commit," so the last command shows exactly what changed in one file.
Read the diff with your failing test in mind. A first bad commit is the commit that triggers the failure. It is not always the line of code that is wrong. A commit can expose a bug that was already present.
Confirm the result
Check the answer yourself before you blame anyone. Test the commit and its parent directly with your script:
git checkout 3f9c2a1 && ./check.sh; echo "culprit exit: $?"
git checkout 3f9c2a1^ && ./check.sh; echo "parent exit: $?"You expect a non-zero exit for the culprit and 0 for its parent. If both give the same result, the search was misled. Common causes are a flaky test, a script that returns the wrong code for some commits, or a build failure that was treated as a plain bad result instead of 125.
Look at the search path
To review which commits Git tested and how it judged each one, print the session log before you reset:
git bisect logEach line records a good, bad, or skip decision with a hash. This is useful when the result looks wrong, because you can see where a commit was marked incorrectly.
Finish the session
Return to your original branch when you are done:
git bisect resetUntil you run this, you stay on a detached HEAD in the middle of the history. After the reset, git show 3f9c2a1 still works, so you can keep reading the culprit from your normal branch.
Next steps once you have the commit
- Read the commit message and diff to form a hypothesis.
- Check whether a later commit already fixed or reverted it with
git log --oneline 3f9c2a1..HEAD -- src/config.c. - Decide on a fix. You can revert the commit with
git revert 3f9c2a1, or write a targeted patch if the commit also holds changes you want to keep. - Add your reproducer as a permanent regression test, so the same failure is caught next time.
Exercise
After git bisect run prints a first bad commit, how can you check that the result is trustworthy, and what does it suggest if the commit and its parent give the same script result?
Show answer
Check out the commit and its parent (3f9c2a1 and 3f9c2a1^) and run the script on each. The commit should exit non-zero and the parent should exit 0. If both give the same result, the search was misled, for example by a flaky test, a script with wrong exit codes, or build failures that should have returned 125.