DEV Community

Nishant Mittal
Nishant Mittal

Posted on

Finding the culprit commit

Hi folks,


I work in an open-source organization with about 11,000 commits on GitHub. Now, recently I ran into a problem i.e. I made a commit a month back and the bug I fixed was not working now. I was unable to find what is the mistake now in the code.

There were about 200 commits since then the repository, now it would be not a good idea, checking out all the commits and find which one broke the feature.

What would you do?

The purpose of this post is asking you what would have you guys done in this case to find the commit that broke the code.

Here's what I did

As GitHub doesn't allow us to get the commit using the commit number i.e. we can't find the 39th commit in a repo by just tweaking the url. But can search a commit by it's hash.

What I tried to do is binary search. Yes, seemed a nice option to me, using this not more than 7-8 commits had to be checked.

But for that I need to get the commits by the commit number. So, I built a app for that.

Github repo -
App -

This app provided me a commit hash by just entering it's number.
Problem solved! I found out the culprit commit by just checking 7 other commits.

But I think it was a little overkill for this problem to build an app. What would you guys have done in such a situation?

Top comments (3)

nas5w profile image
Nick Scialli (he/him) • Edited

There's actually native git functionality to do this: git bisect

This command uses a binary search algorithm to find which commit in your project’s history introduced a bug. You use it by first telling it a "bad" commit that is known to contain the bug, and a "good" commit that is known to be before the bug was introduced. Then git bisect picks a commit between those two endpoints and asks you whether the selected commit is "good" or "bad". It continues narrowing down the range until it finds the exact commit that introduced the change.

nishantwrp profile image
Nishant Mittal

OMG! Didn't know git had this functionality. Thanks for sharing :)

nas5w profile image
Nick Scialli (he/him)

You can be reassured that your instinct to do binary search was so spot-on that git already had a function for it!