Last Updated: February 25, 2016
·
1.661K
· allolex

Use git-bisect when debugging

If you are looking for a bug in a series of commits within git, consider using git-bisect to speed up the process. git bisect start will kick off the process in HEAD, and git bisect bad/git bisect good will mark the current HEAD as buggy (or not) and change HEAD to the next commit.

You will usually start off by marking the current HEAD as buggy and some other earlier commit as good via git bisect good $sha1. The next commit set to HEAD will be equidistant between the last known "bug free" commit and the known buggy commit, i.e. using a binary search algorithm You repeat marking each new commit in HEAD as good or bad until you are left with a single commit which should (ahem!) contain the bug.

If you are unsure about the current HEAD, you can use git bisect skip.

One of my colleagues noted that git-bisect is so good, it's worth learning how to program just so you can use it. Sometime the simplest things are the best.

git-bisect can be used in other cool ways, such as via a script that evaluates to good/bad/skip.

You can read more here: http://git-scm.com/book/en/Git-Tools-Debugging-with-Git