Git bisect is the hero of the week! It turned out that some time between now and three weeks ago, the login functionality broke in the Rails app we’re developing. It didn’t break completely, of course, just in certain environments. And looking at the logs, I had no idea what the error could be, so I just had to work it out from the diff between the last working commit and next. Well, between three developers, there can be quite a few commits during three weeks and with a lesser version control system I would have had to
- checkout the previous revision,
- restart the server (because plugins, gems and even Rails can change between versions),
- try to log in,
- see if works and stop if it does,
- repeat from 1.
With git, I can ask git itself to perform a binary search among all the revisions between now and three weeks ago. It would go like this:
git bisect start HEAD 57c3aaa
,- restart the server,
- try to log in,
- see it fail or succeed,
- say
git bisect bad
orgit bisect good
to make Git checkout the next node in the binary search tree - repeat from 1 until Git says that it found the culprit.
It doesn’t look a lot better, but it is if you have 300 commits. Of course there is nothing to stop you from doing a manual binary search with Subversion, or even to step back one day at a time to narrow it down, and we didn’t actually have 300 commits. But where Git really shines is in the fact that if I can write a program that can tell if a version is good or bad, all I have to do is
git bisect start HEAD 57c3aaa
,git run ../my-test-probe.rb
and sit back and wait. Provided of course that the program also knew how to start and stop the server. Well, here is that program, for your debugging pleasure, and mine:
Recent Comments