🔍 Git Bisect = Binary Search for Bugs
Bug appeared but don’t know when? git bisect finds the exact commit. Binary search through history. Find bugs fast.
📝 Bisect Commands
# Start bisect git bisect start # Mark current commit as bad git bisect bad # Mark known good commit git bisect good commit-hash # Or from specific commit git bisect bad bad-commit-hash git bisect good good-commit-hash # Git checks out a commit # Test if bug exists # Mark as good or bad # Mark current commit as good git bisect good # Mark current commit as bad git bisect bad # Git continues bisect # Repeat until bug found # Show bisect log git bisect log # Reset bisect git bisect reset # Visualize bisect progress git bisect visualize
🎯 Complete Workflow
# 1. Find a bug git log --oneline # abc1234 (HEAD) Latest commit # def5678 Fix something # ghi9012 Bad commit (bug introduced) # jkl3456 Previous good commit # 2. Start bisect git bisect start # 3. Mark bad git bisect bad HEAD # 4. Mark known good git bisect good jkl3456 # 5. Git checks out a commit # Bisecting: 2 revisions left to test after this (roughly 2 steps) # 6. Test the code # Run tests, check for bug # If bug exists: git bisect bad # If bug doesn't exist: git bisect good # 7. Repeat until Git identifies the commit # abc1234 is the first bad commit # 8. Show details git show abc1234 # 9. Reset git bisect reset
✅ Advanced Bisect
- Automate with script: git bisect run test.sh
- Start with good/bad commits
- Use git bisect visualize to see progress
- Save bisect log for later
- Reset after finding bug
“Git bisect finds bugs fast. Binary search through commits. Essential for debugging.”
