AWS Builder Center

How I bisect a broken build with git bisect

A build that passed yesterday fails today. I use git bisect to find the commit that broke it, without reading every diff in between.

Full-stack Developer & Security Researcher
When a build breaks and I do not know which commit did it, I bisect. I do not read every diff. I let git cut the range in half.
First I mark the ends. HEAD is bad, and I pick a commit I know was good, usually the last green build on main.
git bisect start
git bisect bad
git bisect good <commit>
Git checks out a commit in the middle. I run the build. If it passes, I mark it good. If it fails, I mark it bad.
git bisect good
git bisect bad
Each answer cuts the range in half. A range of 100 commits takes about seven builds. When one commit is left, git prints it. That is the commit that broke the build.
Then I check the fix, not the blame. I read the diff of that one commit, fix the break, and run the build again.
Two habits make this work. Mark the good commit from a build you saw pass, not one you assume was fine. And run the same build command at every step, so a pass means the same thing each time.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article