git_bisect
git bisect
Binary search to find bug-introducing commit.
π How Bisect Works
graph LR
A[Good] --> B[...]
B --> C[Bad]
C --> D[Binary Search]
D --> E[Find Bad Commit]
π Start Bisect
Begin Session
git bisect start
Starts bisect session.
Mark Current as Bad
git bisect bad
Marks current commit as having the bug.
Mark Known Good Commit
git bisect good abc1234
Marks a commit where bug didn't exist.
Start with Both
git bisect start HEAD abc1234
Starts with bad (HEAD) and good commit.
π During Bisect
Mark as Good
git bisect good
Current commit doesn't have the bug.
Mark as Bad
git bisect bad
Current commit has the bug.
Skip Current Commit
git bisect skip
Can't test this commit (e.g., doesn't build).
β Finish Bisect
End Session
git bisect reset
Returns to original HEAD and ends bisect.
Reset to Specific Commit
git bisect reset abc1234
Returns to specific commit instead.
π€ Automated Bisect
Run Test Script
git bisect run ./test-script.sh
Automatically tests each commit. Script returns 0 for good, 1 for bad.
Example Test Script
#!/bin/bash
npm test
Simple test script for bisect run.
Run with Command
git bisect run npm test
Uses npm test to determine good/bad.
π View Bisect Log
Show Log
git bisect log
Shows history of bisect session.
Replay Bisect
git bisect log > bisect.log
git bisect replay bisect.log
Saves and replays bisect session.
π‘ Example Session
# Start bisect
git bisect start
# Current commit is broken
git bisect bad
# This old commit worked
git bisect good v1.0.0
# Git checks out middle commit
# Test it, then mark:
git bisect good # or git bisect bad
# Repeat until found
# Git says: "abc123 is the first bad commit"
# End session
git bisect reset
π‘ Tips
Use Automated Testing
Bisect is most powerful with automated tests.
Visual Bisect
git bisect visualize
Opens visual representation.
π Related
#git #bisect #debug #advanced