🔍 Binary Search Through Git History
Bug appeared sometime. Which commit? Git bisect does binary search through commits. Find culprit in O(log n) steps.
🔧 Manual Bisect
# Start bisect git bisect start # Mark current commit as bad (bug exists) git bisect bad # Mark a known good commit (no bug) git bisect good v1.0.0 # Git checks out middle commit # Test the commit # Mark as good or bad git bisect good # if no bug git bisect bad # if bug exists # Repeat until culprit found # Git shows the commit that introduced the bug # End bisect session git bisect reset
🤖 Automated Bisect with Script
# Create test script that returns 0 for good, non-0 for bad git bisect start HEAD v1.0.0 git bisect run npm test # Or with custom script git bisect run ./test.sh # Example test.sh: #!/bin/bash npm run build npm run test:integration exit $?
💡 Advanced Commands
- git bisect visualize → See commits with gitk
- git bisect log → Show bisect history
- git bisect skip → Skip current commit (if untestable)
- git bisect terms → Customize ‘bad’/’good’ terms
“Bug appeared 200 commits ago. Manual search would take hours. Git bisect found the exact commit in 8 steps. The commit message: ‘Fixed typo’ — it actually broke everything.”
