Isolating with Bisection
Halve the search space repeatedly to pinpoint what broke — including with git bisect.
Bisection is binary search applied to debugging. Instead of inspecting every possibility, you repeatedly split the search space in half and ask “is the problem before or after this point?” Each test eliminates half the candidates, so even hundreds of commits or config lines collapse to a handful of checks.
You bisect across time (which commit introduced the bug?), space (which
half of the config/file?), and components (disable half the services). Git
automates the commit case with git bisect: you mark a known-good and a
known-bad commit, and it checks out the midpoint for you to test.
git bisect start
git bisect bad # current commit is broken
git bisect good v1.2.0 # this old tag worked
# Git checks out the midpoint — test it, then:
git bisect good # or: git bisect bad
# ...repeat until Git names the first bad commit...
git bisect reset # return to where you wereNon-code bisection: comment out half a config, retest; if fixed, the problem was in that half — narrow again.
- Use
git bisecton a repo to find a commit that introduced a change. - Describe how you’d bisect a 200-line config file to find a bad setting.
- Calculate how many steps it takes to bisect 256 candidates.
- Explain when bisection beats reading code top-to-bottom.
Cheat Sheet▾
| Task | Command / idea |
|---|---|
| Start | git bisect start |
| Mark current bad | git bisect bad |
| Mark known good | git bisect good <ref> |
| Continue | mark each checkout good/bad |
| Finish | git bisect reset |
| Automate | git bisect run <test-cmd> |
| Config/space | disable half, retest |
Common Interview Questions▾
What is bisection in troubleshooting?
Binary search for the cause: repeatedly split the search space in half and test which half contains the problem, eliminating half the candidates each step.
How does git bisect help find a regression?
You mark a good and a bad commit; git checks out the midpoint for you to test and narrows down, in log2(N) steps, to the exact commit that introduced the bug.