git bisect for the impatient

I was testing Slugathon last night and found a bug.  Unfortunately, it was a GUI bug so my unit tests didn't catch it.  Luckily, the bug was easy to reproduce (I could see it in about ten seconds from the start of a new game).  So here's how I used git bisect to find which commit had the bug.  (Note: I had a clean tree with no uncommitted changes at the start of the process.  If I had uncommitted changes I would have used git stash first.)


$ git bisect bad

You need to start by "git bisect start"

Do you want me to do it for you [Y/n]? Y

$ git checkout HEAD~10

$ ./setup.py build; sudo ./setup.py install; ./slugathon server

(Did not see the bug.)

$ git bisect good

Bisecting: 4 revisions left to test after this (roughly 2 steps)
[b1b94b6253ad506cb03199bea6ff52e76ebedfb9] Remove some obsolete TODO comments.

$ ./setup.py build; sudo ./setup.py install; ./slugathon server

(Did not see the bug.)

$ git bisect good

Bisecting: 2 revisions left to test after this (roughly 1 step)
[cb7b8c2553f48a6d2a8c8eca5cb538927720874c] Rename Player.legions to markerid_to_legion

$ ./setup.py build; sudo ./setup.py install; ./slugathon server

(Did not see the bug.)

$ git bisect good

Bisecting: 0 revisions left to test after this (roughly 1 step)
[d0a783c61eba6ba5f70b3021252a46f301293727] Update legion and marker counts after StartMusterPhase.

$ ./setup.py build; sudo ./setup.py install; ./slugathon server

(Did not see the bug.)

$ git bisect good

69efbfd5e19220e46f588944a8692140933cb303 is the first bad commit
commit 69efbfd5e19220e46f588944a8692140933cb303
Author: David Ripton <dripton@ripton.net>
Date:   Mon Dec 5 21:34:36 2011 -0500

Rename Player.markerids to markerids_left for clarity.

$ git bisect reset

And that's all; it found which commit had the bug. I did a git log -p on that commit to see exactly what I'd changed, found a suspicious part of the patch a few minutes later, fixed it, verified the bug was fixed, and committed and pushed the fix. Easy.

Of course you can do this without git bisect; it just saves you the effort of manually doing the binary search through the range of possibly-bad commits.