Skip to content

Instantly share code, notes, and snippets.

@aryehbeitz
Forked from stevenyap/Git_Bisect.md
Last active October 26, 2022 08:34
Show Gist options
  • Save aryehbeitz/fa95af333b26c8e7ad61f3276f6c5e14 to your computer and use it in GitHub Desktop.
Save aryehbeitz/fa95af333b26c8e7ad61f3276f6c5e14 to your computer and use it in GitHub Desktop.
Finding bugs in Git commits using git bisect

You have a git commit in your history that is causing a bug but you do not know which commit it is. Here's how to use git bisect to find the commit that causes the bug.

# in the git root, start the git bisect
git bisect start

# mark current commit as bad
git bisect bad

# tell git which is the commit is good (it can be any good commit in the far history)
git bisect good <commit-hash>

# git will tell you roughly how many revisions you need to find the bad commit
# eg. Bisecting: 24 revisions left to test after this (roughly 5 steps)
# You are now at a commit that is chosen by git bisect
# Run your test to determine if the commit is okay

# if commit is okay, then
git bisect good

# if commit is bad, then
git bisect bad

# Repeat the above until git tells you which is the bad commit
# eg. f5836a61c5e989b972499e5265760519580d3cfe is the first bad commit
# Note down your bad commit hash

# Upon finishing, then
git bisect reset

# Work on your bad commit!!!

332e851383112e4505794e7c3096386868816c25

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment