Satya's blog - Git bisect

Jul 13 2022 07:59 Git bisect

For those that don't know, and those that do, git bisect is a very cool tool/strategy/usage to find out the answer to "which commit broke everything?" I used it recently. I have a page which suddenly started showing blanks instead of the numbers that should be there. So I used git bisect. First I did `git bisect start`.

I knew this was on my "test" branch, so I checked that master was good (it was), and that the tip of test was bad (it was), so I marked both of them with `git bisect good` and `git bisect bad`.

Then I just kept reloading the page, marking each commit as good or bad depending on whether the numbers showed or not.

`git bisect` does the work of checking out the "next" commit after you name two commits good and bad. It does a binary search, so it checks out a commit half-way between the last-marked good and bad ones, and if you mark that one good/bad it moves HEAD to half-way between that one and bad/good. It's cool to watch in action.

https://git-scm.com/docs/git-bisect

You can also use this to find the "commit that introduced the change", it doesn't have to be a breaking change. Just so long as you have a quick way to test whether a particular commit falls on the "good" or "bad" side. In my case, that was just reloading the page to see if numbers showed up. Other ways are to run a unit test, run a script, or whatever.