Skip to main content

Finding the bug with git-bisect

·204 words·1 min

Imagine you’re working on a project and one day you realize that a component has stopped working. The logs give no clue as to where the problem is. The component’s codebase is so large it would take forever to debug it. Tests don’t help identify the issue either. But here’s an important detail—you know that in the previous version, the component worked fine. What would you do to find the faulty code?

You could probably come up with several answers to that question, but today we’re going to talk about a Git operation that can help you solve this issue: git bisect

By using the git bisect command, we can identify the exact commit that introduced the bug into our software. Under the hood, git bisect performs a binary search, starting from a good version and a bad version.

As a practical exercise, I’ve created a GitHub repository with the steps to follow if you want to try out git bisect yourself. Don’t worry, you’ll only need a terminal. The project includes a simple Bash script that prints whether a given version is working or broken. This way, we can simulate a real-world scenario.

🖼️ Insects, Butterflies, and a Grasshopper. 1664. Jan van Kessel

Related

Antipattern: Lava Flow
·346 words·2 mins
Monkey patches
·340 words·2 mins