« Back to Index

Using git bisect to find where a bug was introduced

View original Gist on GitHub

git bisect.md

http://git-scm.com/docs/git-bisect

git bisect start
git bisect bad # to indicate current commit is broken
git bisect good {commit} # to indicate the last good commit

# at this point git will set HEAD to a specific commit within
# the specified range of good->bad commits.
#
# you'll now run your code and if the code is working, you'll
# mark it as a 'good', otherwise if the code is still broken
# you'll mark it as 'bad'.
#
# once you're done going through all the necessary commits
# git will tell you which commit introduced the bug.

git bisect bad|good # you'll run this command over and over while Git changes commits to find which commit introduced the bug
git bisect reset # to bail out of everything and move back to original HEAD (i.e. the latest broken commit)

You can also filter what commits are included in a bisect like so:

git bisect start -- ./sub_directory

This will mean only commits that affected files inside of ./sub_directory are considered.

Note: you can also specify a range of commits to skip: git bisect skip 0dae5f ff049ab ...