Git & Version Controladvanced
Automate git bisect to find the commit that introduced a bug
Git Bisect Helper
Automate git bisect to find the commit that introduced a bug
Automate git bisect to find the commit that introduced a bug.
Instructions
- Identify a "good" commit (where the bug didn't exist):
git log --oneline -20 # find a known good point
- Start bisect:
git bisect start
git bisect bad # current commit is bad
git bisect good <good-commit> # known good commit
-
At each step, test if the bug exists:
- Run the failing test:
npm test -- --grep "test name" - Or check manually
- Then mark:
git bisect goodorgit bisect bad
- Run the failing test:
-
Automated bisect (if you have a test):
git bisect run npm test -- --grep "failing test name"
# Or with a custom script:
git bisect run bash -c 'npm run build && npm test'
- When bisect finds the commit:
git show <bad-commit> # review the culprit
git bisect reset # return to original branch
Tips
- If a step can't be tested (e.g., won't compile):
git bisect skip - Bisect is O(log n) — 1000 commits takes ~10 steps