bashintermediate
Git Bisect — Find the Commit That Broke It
Use binary search across commits to pinpoint exactly which commit introduced a bug or regression.
bashPress ⌘/Ctrl + Shift + C to copy
# Start bisect session
git bisect start
# Mark current commit as bad (has the bug)
git bisect bad
# Mark a known good commit (before the bug)
git bisect good v2.1.0
# Git checks out a middle commit. Test it, then:
git bisect good # if this commit works
git bisect bad # if this commit is broken
# Repeat until Git finds the exact bad commit:
# "abc1234 is the first bad commit"
# End bisect and return to original branch:
git bisect reset
# --- Automated bisect with a test script ---
git bisect start HEAD v2.1.0
git bisect run npm test
# Git runs 'npm test' on each commit automatically,
# marks good/bad based on exit code (0 = good, 1+ = bad).
# Automated bisect with custom script:
git bisect run bash -c 'grep -q "expectedFunction" src/app.ts'Sponsored
GitHub Copilot
Use Cases
- Finding which commit introduced a regression
- Automating bug-hunting with test scripts
- Narrowing down performance degradation causes
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
bashadvanced
Git Bisect to Find a Bug
Use binary search through commit history with git bisect to find the exact commit that introduced a bug.
Best for: Finding which commit introduced a regression
#git#bisect
bashintermediate
Git Blame Investigation Techniques
Use git blame and related tools to trace code authorship and understand change history.
Best for: Finding who introduced a bug
#git#blame
bashintermediate
Git Hooks Pre Commit
Git workflow: git-hooks-pre-commit
Best for: version control
#git#version-control
bashadvanced
Git Hooks Post Commit
Git workflow: git-hooks-post-commit
Best for: version control
#git#version-control