The export worked in last month's release. In this month's release, it produces an empty file. Nobody remembers touching it, and the history between the two versions contains about three hundred commits from six people. You could start reading them one by one. There is a much faster way, and it is built into Git.
The command is git bisect. It does a binary search through your history. You tell it one commit where the problem exists and one where it did not. It checks out a commit roughly halfway between them, and you test that version. Depending on your answer, it throws away half of the remaining commits and picks the middle of the other half. Each answer halves the search. Three hundred commits take at most nine steps.
A session looks like this. Run git bisect start. Then git bisect bad to mark the current commit as broken, and git bisect good followed by the tag of the last release that worked. Git checks out a commit in the middle. Build it, run the export, and type git bisect good or git bisect bad. Repeat until Git prints the first bad commit, with its author and message. When you are finished, run git bisect reset to return to where you started.
Two things make it work well. First, you need a quick and reliable way to tell good from bad. If you can write a small script that exits with zero when the export works and with one when it is broken, you can hand the whole job to Git with git bisect run followed by the script. It will test every step for you while you get a coffee.
Second, some commits in the middle will not build at all, or will fail for a different reason. Do not guess. Run git bisect skip, and Git will choose a nearby commit instead.
The result is not always the answer, but it is a very good place to start. You now have one commit, usually a small diff, and the name of someone who can explain why it changed.
Try it once on a bug you have already fixed, so it feels familiar before you need it for real.
– Asael Shinder
Top comments (0)