DEV Community

Brandon Rozek
Brandon Rozek

Posted on • Originally published at brandonrozek.com on

Which commit broke the build? Using Git Bisect

Lets imagine a scenario where in the latest merge a test starts failing. Lets say these tests are saved in test.sh. Instead of having to test each individual commit in the merge, to see where the test fails, luckilygit bisect narrows it down in a more efficient way!

To use:

git bisect start [good] [bad]
git bisect run test.sh

Enter fullscreen mode Exit fullscreen mode

Where [good] and [bad] are replaced with their respective commit hashes.

Under the hood, Git will run a binary search between the good and bad nodes in the commit tree.

As a reminder, don’t forget to make test.sh an executable. Starting in Git 2.36 it will provide a warning, but earlier versions will perform the search anyways even with it all failing.

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

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay