Frequently Asked Question
How does git bisect find the commit that introduced a bug?
git bisect is a binary search over your commit history. You start by telling Git a
good commit (the bug was not present) and a bad commit (the bug is present),
usually HEAD. Git checks out the commit halfway between them and asks you to test;
you reply git bisect good or git bisect bad, and Git halves the search space again.
After roughly log₂(N) steps it converges on the single commit that introduced the
regression. For a thousand-commit range that is around ten checkouts, minutes of
work to locate a regression that might otherwise be untraceable.
Bisect can be fully automated. If you have a script or test that returns 0 when the
code is good and non-zero when it is bad, git bisect run ./test.sh performs the
whole search without further input. This is wildly effective when combined with a
project's CI test suite. When you are done, git bisect reset returns you to your
original branch.