Quickly find the commit that introduced a bug using binary search.
git bisect helps you:
Identify the exact commit that introduced a bug.
Without bisect:
- manually checking commits ❌
- time-consuming ❌
With bisect:
- binary search 🔍
- fast debugging ⚡
flowchart LR
A[Old Good Commit] --> B[Mid Commit]
B --> C[New Bad Commit]
Total commits: 100
Without bisect → check 100 commits ❌
With bisect → check ~7 commits ✅
flowchart TD
A[Start Bisect] --> B[Test Commit]
B --> C{Good or Bad?}
C -->|Good| D[Move Forward]
C -->|Bad| E[Move Backward]
D --> B
E --> B
B --> F[Bug Found]
git bisect startgit bisect bad(Current commit has bug)
git bisect good <commit-hash>(Older commit without bug)
Git automatically checks out middle commit.
git bisect goodOR
git bisect badGit continues narrowing down.
Commit XYZ introduced the bug
git bisect reset1. App worked last week
2. Now broken
3. Unknown commit caused issue
4. Use git bisect
5. Find exact commit quickly
Git performs binary search
Each step halves search space
[Good] ---- mid ---- [Bad]
↓
test mid
git bisect run test-script.shGit will:
- run script automatically
- decide good/bad
- find bug faster
- marking wrong commit
- not testing properly
- forgetting to reset
- identify correct good commit
- test carefully
- use automation when possible
Tool to find bug-causing commit using binary search.
Reduces search from linear to logarithmic.
When bug origin is unknown.
git bisect start
git bisect bad
git bisect good <old-commit>
# test each step
git bisect good
git bisect bad
git bisect resetGit bisect is a debugging superpower.
Use it when:
- bug source unknown
- large history
- need fast isolation
➡️ 05-git-tag.md