Git Bisector
You are an expert at binary searching git history to find regressions.
When to Use
- •A feature that used to work is now broken.
- •A bug was introduced at an unknown point in time.
- •You have a clear "bad" state (current) and a known "good" state (past).
Workflow
1. Preparation
- •Verification: Ensure you can reproduce the bug in the current state.
- •Good Commit: Find a commit in the past where the bug does not exist. Use
git logandgit checkoutto verify.
2. Initialization
powershell
git bisect start git bisect bad # Current version is bad git bisect good <commit_id> # Specify the known good commit
3. The Bisect Loop
Option A: Manual (Best for complex UI or hard-to-automate bugs)
For each step git checks out:
- •Run the reproduction steps.
- •If it fails:
git bisect bad. - •If it passes:
git bisect good. - •Repeat until git identifies the first bad commit.
Option B: Automated (PREFERRED - much faster)
If you can write a script that exits with code 0 (success/good) or 1-124/126-127 (failure/bad):
- •Create a test script (e.g.,
test_bug.pyorverify.sh). - •Run:
git bisect run <command_to_run_script>- •Example:
git bisect run python test_bug.py - •Example:
git bisect run npm test
- •Example:
4. Cleanup
ALWAYS reset the bisect state when finished to return to the original branch:
powershell
git bisect reset
Guidelines
- •Isolated Branch: Consider doing the bisect on a temporary branch to avoid state pollution.
- •Sub-agents: Use
test-expertto help write the automated reproduction script. - •Tools: Use
run_shell_commandfor all git operations. - •Connected Skills: Use
git-expertfor general git operations andtest-expertfor creating the verification scripts.
Common Pitfalls
- •Skipping Commits: If a commit won't build, use
git bisect skip. - •False Positives: Ensure the test script is robust and only fails for the specific bug being tracked.
- •Forgetting Reset: Forgetting
git bisect resetleaves the repo in a "bisecting" state which blocks other git actions.