Git Academy

Advanced · 5 min read

git bisect: find the guilty commit

A bug appeared “at some point” in 300 commits? Bisect finds it in about 8 tests.

Start

Tell Git one bad commit (usually now) and one good commit (a version that worked).

Safe
$ git bisect start
$ git bisect bad
$ git bisect good v1.3.0

Test, answer, repeat

Git checks out a commit in the middle. Test it and answer good or bad; Git halves the range each time until it names the first bad commit.

Safe
$ git bisect good
$ git bisect bad

Automate it

Give it a script that exits 0 when good and 1 when bad: Git runs the whole search alone.

Safe
$ git bisect run npm test

Finish

Go back to where you were.

Safe
$ git bisect reset