Wednesday, 26 September, 2018 UTC


Summary

Do you guys know git bisect works? This is one of this features you don’t end up to use often but when you do this is completely mind-blowing.
So here’s a recent example. I received a bug report from one of the managers, and it was quickly apparent the problem was that one of the files was missing a function. But I didn’t know what that function looks like and when/why it was deleted, so I needed to find the commit in which this change took place.
Git bisect to the rescue!
Git bisect is a tool that can run some test command on different commits to figure out the first commit that went out of hand.
First, we need to figure out the command. That can be your test suit, or in our case is a simple grep expression, like this grep initApp scr/app.js.
Make sure for whatever command you run, it should return 0 for good commits and not 0 for bad commits. You can check what your command returns by running it and then checking echo $?. More on dollar vars here.
So, we start with
1) git bisect start HEAD aabbcc --. Here the HEAD is the bad commit, aabbcc is the last known good one.
2) git bisect run grep initApp scr/app.js running our command. By this point, git will happily report the first bad commit!
3) Don’t forget to git reset to quit the bisect mode.
That’s pretty much. Enjoy bisecting!