Luke Oliff.

TIL: Using git bisect To Find the Commit That Broke a Build

·TIL·1 min read·Luke Oliff

A feature broke. You do not know when. You have 50 commits since it last worked. git bisect finds the culprit in 6 steps.

git bisect start
git bisect bad          # current commit is broken
git bisect good abc123  # abc123 was working

Git checks out the midpoint commit. Test it. Tell git whether it is good or bad.

git bisect good   # this commit works
git bisect bad    # this commit is broken

Each step halves the remaining range. Within log2(N) steps git identifies the exact commit that introduced the breakage.

git bisect run npm test

For automated bisects, git bisect run uses the exit code of any command. Tests pass means good, fail means bad. Walk away and come back to the answer.

How do I exit bisect mode?

git bisect reset returns your repo to the original state before the bisect started.