Git Bisect

Git Bisect

Bisect performs a binary search through your commit history to find which commit introduced a bug. Instead of checking each commit one-by-one, it halves the search space at every step.

Manual bisect

$ git bisect start
$ git bisect bad                    # current commit has the bug
$ git bisect good <hash>            # this older commit was fine

Git checks out a midpoint commit. Test it, then mark it:

$ git bisect good                   # midpoint is clean
$ git bisect bad                    # midpoint has the bug

Repeat until Git identifies the first bad commit, then clean up:

$ git bisect reset                  # return to original branch

Automated bisect with a test script

If you have a script that exits 0 for good and non-zero for bad, bisect can run unattended:

$ git bisect start HEAD <good-hash>
$ git bisect run ./test.sh

Git runs the script at each midpoint and reports the first bad commit when done.

Tips

For blame, log search, and other debugging tools, see the Debugging recipe.

On this page