What this thread does
The problem
Something that worked at an earlier commit is broken now, across dozens of commits (many written by an agent). Asking the agent to "find the cause" often turns into guessing from the current code.
What the git manual says
git bisect (read 18 October 2026):
git bisect start, thengit bisect badfor the broken revision andgit bisect good <rev>for a known-good one. Git checks out a middle commit and reports roughly how many steps remain.git bisect run <cmd>automates it. Exit code 0 means good; 1 to 127 except 125 means bad; 125 means "cannot be tested, skip"; other codes abort. The manual's example:git bisect start HEAD HEAD~10 --, thengit bisect run sh -c "make || exit 125; ~/check_test_case.sh", thengit bisect reset.git bisect skipskips untestable commits, but skipping a commit next to the culprit means git cannot name the exact first bad one.- The manual says it is safer if the test scripts are outside the repository, so they do not interact with the checkouts.
How to describe it to your agent
The behaviour <X> worked at <tag or commit> and is broken at HEAD. Write a single script outside the repo that exits 0 when it works and 1 when it fails (use exit 125 if the build itself fails), run it withgit bisect run, thengit bisect reset. Show me the first bad commit and its diff, and only then propose a fix. Do not run bisect on a dirty working tree.
Mistakes to check
- A flaky check: the search will land on a random commit. Run the script three times on a known-good and a known-bad commit first.
- Test script inside the repo, so it is overwritten or missing when commits change.
- Uncommitted changes in the working tree blocking checkouts.
- Forgetting
git bisect reset, leaving the repo on a detached commit.
Limits
From the git manual; I did not run this on a real regression, and I found no community thread about doing it with agents.
Sources
Primary source, read on 18 October 2026: the git bisect manual.
- Confirms:
git bisect runexit codes (0 good; 1 to 127 except 125 bad; 125 skip; other codes abort), the manual's example withmake || exit 125andcheck_test_case.sh,git bisect start HEAD HEAD~10 --,git bisect reset, the advice to keep the test scripts outside the repository, and the warning that skipping a commit next to the culprit leaves git unable to name the first bad one. - Not on the manual: the thread's prompt wording and the flaky-test and dirty-tree cautions are its own advice.
Started from a post by @Git project (git-bisect manual), packaged by the editor. Original post