Binary Search for Bug Introduction
Git · History & Inspectionsyntax
git bisect start
git bisect bad [commit]
git bisect good <commit>example
git bisect start
git bisect bad # Current commit is broken
git bisect good v1.0.0 # This tag was working
# Git checks out a middle commit, you test it:
# If it's good:
git bisect good
# If it's bad:
git bisect bad
# Repeat until Git finds the first bad commit
git bisect reset # Return to original branchoutput
Bisecting: 8 revisions left to test after this (roughly 3 steps)
a1b2c3d is the first bad commitNote Bisect uses binary search to find the exact commit that introduced a bug. For N commits, it takes at most log2(N) steps. You can automate it with: git bisect run <test-script>