Full Byte Developer.

Find the commit that broke your tests with git bisect run

Three commands that binary-search your commits and print which one first failed your test.

Published here , tested on Git 2.54.0 · 1 source

Twelve commits from your AI agent and one of them broke the tests? Git can find that commit for you. Start, run, reset.

Mark the broken commit and the last good one

Tell bisect where to search [1]. HEAD is broken, and you know an earlier commit that passed.

bash
git bisect start HEAD <last-good-commit>

You should see "Bisecting: N revisions left to test after this".

Let git run your test on each step

Bisect checks out commits in binary-search order and runs your test on each one [1].

bash
git bisect run npm test

How it decides: your test exits 0 for a good commit, 1 to 127 (except 125) for a bad one. Exit 125 means "cannot test this one, skip it". Any other exit code stops the bisect.

You should see bisect print "is the first bad commit" when it finishes.

Go back to where you were

Reset puts you back on the branch you started from [1].

bash
git bisect reset

You should see "Previous HEAD position was..." and then your original branch name.

What it needs

Commit after every agent step (or ask your agent to), so each change can be tested on its own. A test that fails the same way every run. A flaky test sends bisect down the wrong half.

No test script yet? Any command that exits 1 on failure works:

bash
git bisect run python3 test.py

In my test repo (git 2.54.0): 12 commits on top of a passing base, a bug I placed in commit 8 (sum of all items became sum of all but the first). git bisect run npm test ran the test 4 times (commits 6, 9, 8, 7) and printed "is the first bad commit" for commit 8.

You now have three commands that find the breaking commit without reading diffs one by one.

Send this to the friend staring at twelve agent commits trying to guess which one broke the tests.

Keep this guide

By Full Byte Developer

Filed under Dev tools

Questions about this guide

What if a commit cannot be tested?

Exit 125 tells bisect to skip that commit. It picks another one and continues the search.

Does bisect work without a test script?

Yes. Run git bisect start, then git bisect good or git bisect bad after checking each commit yourself. The run command automates that.

Sources

Next in this stack