Understanding Git Bisect
Software developers generally use a version control system like git to save and manage the history of the code they write. When they add a new feature or fix a bug, they "commit" these changes to their code repository.
As a project moves forward, developers may discover that some existing feature or behavior has broken. Often it's not clear why this functionality broke, and searching through dozens of commits and files to debug the issue can be painful.
Thankfully, the git version control system has a feature called "bisect" that can be helpful in these scenarios. This document offers an interactive visualization to help understand how git bisect works and why it's so effective.
Discovering an Issue
Imagine we're working on an app that renders a collection of fun shapes. Unfortunately it appears that the star shape got misaligned at some point, but its unclear when or why.
We know that it was working when we launched v1 of the app last month, but there have been dozens of changes since then and finding the problematic commit would be tedious.
Bisecting the Issue
Git bisect allows you to do a binary search of the commits between a known good and known bad commit. Because it uses a binary search, you will need to verify at most log(n) commits – which is much easier than manually checking all commits one by one.
Use the interactive tool below to see how git bisect works in action:
How Bisect Scales
This chart shows how the number of steps required to perform a git bisect scales with the number of commits that fall between the known good and known bad commits.
You can see that even if there are ten thousand commits to search through, we can still find the problematic commit in roughly 14 steps. This is a non-intuitive concept that really illustrates the power of git bisect and binary searches in general.
Using the following tool you can visualize how long a git bisect will take, even when there are thousands of commits to search:
Summary
Leveraging the speed of log(n) binary searches, git bisect can be a powerful tool in the software developer utility belt. Hopefully this document helped illustrate how it works and why its so effective.
Source Code: github.com/schnerd/git-bisect