Sub topic 3
Reading the Result of `git bisect run`
Assume you are comfortable with commits, branches, tags, and shell commands. You also need to read a test script’s exit status.
Identify the first bad commit
When the automated search finishes, Git prints a commit marked as the first bad commit:
abc1234 is the first bad commit
commit abc1234 ...Inspect that commit before changing anything:
git show --stat abc1234
git show --format=fuller abc1234
git log --oneline --decorate -5 abc1234git show displays the commit message and patch. Check whether the changed files and message explain the regression. The first bad commit is the boundary Git found between a known good state and a known bad state. It may expose the cause directly, or it may only narrow the investigation.
Save, replay, and end a session
Save the recorded decisions before resetting:
git bisect log > bisect.log
git bisect resetTo reproduce the same search later, start from a normal checkout and replay the log:
git bisect replay bisect.logAlways run git bisect reset when you finish. It returns the working tree to the branch or commit you had checked out before the search.
Use clearer terms
For regressions where “old” and “new” are clearer than “good” and “bad,” define custom terms:
git bisect start --term-old=working --term-new=broken
git bisect working v1.4.0
git bisect broken HEAD
git bisect run ./check.shGit then asks for working or broken instead of good or bad.
Handle merges and flaky tests
--first-parent searches the mainline through merge commits:
git bisect start --first-parent HEAD v1.4.0
git bisect run ./check.shUse it when you want the merge that introduced a change, rather than a commit inside the merged branch.
Flaky tests can misclassify a commit. Run the test repeatedly and require a stable result. If the result changes, return 125 so Git skips that commit:
#!/bin/sh
passes=0
fails=0
for attempt in 1 2 3 4 5; do
./run_regression_test.sh && passes=$((passes + 1)) || fails=$((fails + 1))
done
if [ "$passes" -ge 4 ]; then exit 0; fi
if [ "$fails" -ge 4 ]; then exit 1; fi
exit 125Exercise
Which command restores your original branch after a bisect?
Show answer
git bisect reset.