From grimoire
Use git bisect to binary-search commit history and identify the exact commit that introduced a regression.
How this skill is triggered — by the user, by Claude, or both
Slash command
/grimoire:bisect-regressionThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Use `git bisect` to binary-search commit history and identify the exact commit that introduced a regression — reducing a search across thousands of commits to O(log n) steps.
Use git bisect to binary-search commit history and identify the exact commit that introduced a regression — reducing a search across thousands of commits to O(log n) steps.
Adopted by: git bisect is a built-in Git command used by the Linux kernel team (Torvalds designed it for this purpose), Google, Mozilla, and any team using Git for version control; Chacon & Straub's "Pro Git" (the canonical Git reference at git-scm.com) dedicates a section to git bisect as the primary tool for locating regressions; the git bisect run subcommand enables full automation, making it suitable for CI regression detection
Impact: Binary search finds the culprit commit in ⌈log₂(n)⌉ steps — 10 commits to check in a 1,000-commit history, 17 in a 100,000-commit history; without bisect, engineers manually read commit history, which takes O(n) time; git bisect run with an automated test script reduces a multi-hour manual investigation to under 5 minutes for most repositories; the Linux kernel team uses automated bisect to find regressions across tens of thousands of commits
Why best: Reading commit messages and diffs to find a regression is O(n) and error-prone — commits are often grouped by feature, not by the system component that regressed; git bisect bypasses reading and directly identifies the offending commit by testing behavior; the alternative (blaming based on recent changes) misses regressions introduced by seemingly unrelated commits
Sources: Chacon & Straub "Pro Git" 2nd ed. Ch. 7 "Debugging with Git" (git-scm.com/book/en/v2); Git documentation "git-bisect" (git-scm.com/docs/git-bisect); Torvalds on bisect design (lkml.org)
Before starting bisect, establish two reference points:
# Current HEAD is broken → this is "bad"
# Find a known-good commit: last release tag, a recent passing CI build, or "it worked last week"
git log --oneline -20 # scan recent commits
git tag --sort=-creatordate # list tags newest-first; recent release tags are good candidates
You need:
HEAD)The range between good and bad is what bisect will search. Wider range = more steps, but bisect is still fast: 100 commits = 7 steps; 10,000 commits = 14 steps.
git bisect start
git bisect bad # mark HEAD (current) as bad
git bisect good v2.3.1 # mark a known-good tag or SHA
Git immediately checks out the midpoint commit between good and bad:
Bisecting: 47 revisions left to test after this (roughly 6 steps)
[abc1234] Some commit message
At each midpoint, test whether the behavior is broken:
# Run your test, build, or manual check
npm test -- --grep "the failing behavior"
# OR
./run-specific-test.sh
# OR manually test the feature
Then tell bisect the result:
git bisect good # this commit does NOT have the bug
git bisect bad # this commit DOES have the bug
Git checks out the next midpoint. Repeat until bisect outputs:
abc1234 is the first bad commit
commit abc1234
Author: Someone <[email protected]>
Date: Mon Jan 1 12:00:00 2024
feat: add new cache invalidation logic
git bisect run (preferred)If you have an automated test that reliably reproduces the bug, automate the entire process:
git bisect start
git bisect bad HEAD
git bisect good v2.3.1
git bisect run npm test -- --grep "the failing behavior"
git bisect run rules:
0 = good (test passes = no bug)1–127 (except 125) = bad (test fails = bug present)125 = skip this commit (cannot test — e.g., won't compile)# Example: run a single test file
git bisect run python -m pytest tests/test_cache.py::test_invalidation -x
# Example: shell script that builds and tests
git bisect run ./scripts/bisect-test.sh
For repositories that sometimes fail to compile at intermediate commits, use 125 skip:
#!/bin/bash
# bisect-test.sh
make || exit 125 # skip if build fails
./run-test.sh # 0 = good, non-zero = bad
Once bisect identifies the first bad commit:
git show abc1234 # full diff of the offending commit
git log --stat abc1234 # files changed
Read the diff with the bug in mind. The regression is in this commit. Common patterns:
git bisect reset # returns HEAD to the original branch/commit
Always run git bisect reset when done — it restores the working tree to its pre-bisect state. Forgetting leaves you on a detached HEAD at the last-tested commit.
With the offending commit identified:
write-regression-test)git bisect reset at the end — never leave the repo in detached HEAD stategit bisect run must be deterministic — flaky tests produce wrong good/bad assignments and lead bisect to wrong commits125 to skip commits that can't be tested — never force a bad/good verdict on an untestable commitgit bisect reset: leaves repository in detached HEAD state; git status will show "HEAD detached at abc1234"; fix by running git bisect reset or git checkout maingit bisect run: manually testing 15 commits one by one when an automated test exists; git bisect run reduces a 30-minute process to 2 minuteswrite-regression-test), then bisectnpx claudepluginhub jeffreytse/grimoire --plugin grimoireAutomates git bisect to pinpoint the commit introducing a regression by running tests during binary search, showing diff and blame info, and generating analysis reports.
Pinpoints the commit introducing a bug or regression using git bisect binary search. For performance regressions, recent test failures, or issues that previously worked.
Using bisect/git bisect to isolate failure to exact commit or code path.