DEV Community

Cover image for Track Down Pesky Bugs with `git bisect`

Track Down Pesky Bugs with `git bisect`

Tyler Hawkins on March 12, 2020

Recently I’ve come across a couple dev issues that were incredibly difficult to track down. Normally, fixing a bug in JavaScript is as simple as r...
Collapse
 
joeattardi profile image
Joe Attardi

git bisect is a life saver! It has saved my bacon several times. If you have automated tests, you can even run bisect on autopilot, if the test has a 0 exit status, it treats it as good, if it has a non-zero exit status, it treats it as bad. Just start it, go get some coffee, and come back to find your bad commit!

see here for more details: lwn.net/Articles/317154/

Collapse
 
thawkin3 profile image
Tyler Hawkins

Neat! Thanks for sharing.

It seems like if you're using a continuous integration model though where your tests are always running on each commit, and it's required that your tests pass before you're allowed to merge your new code into the master branch, you wouldn't end up in a situation in which you have failing tests on your master branch. Right?

So is automating git bisect assuming that you're not enforcing 100% passing tests? Or would you run it on your own branch in which you have multiple commits that haven't had their tests validated and you've introduced a bug somewhere in there, but you still haven't merged to master yet? Or what's the use case here?

Collapse
 
joeattardi profile image
Joe Attardi

That's a good point.

I think the use case would be if you uncover a bug that you don't have an automated test for, but you can then write one that reproduces the bug. Then you run git bisect in automatic mode. Once the issue is fixed, you can add that new test to your test suite. 🤷‍♂️That's the best one I can think of.

Collapse
 
rhymes profile image
rhymes

Ooh didn't know about git bisect run.

Wouldn't that be too slow for web apps that have no compilation step?

Collapse
 
rhymes profile image
rhymes

Love this article Tyler, thanks! You gave me an idea about using rspec bisect to track down bugs in Rails tests :-)

Collapse
 
thawkin3 profile image
Tyler Hawkins

Thank you! Glad you liked it.

Collapse
 
rhymes profile image
rhymes

Great explanation Tyler!

Collapse
 
sankarsanjay profile image
Sanjay Sankar

Damn. This was actually mindblowing! Thanks for sharing!

Collapse
 
thawkin3 profile image
Tyler Hawkins

You’re welcome! Glad you enjoyed it.

Collapse
 
waylonwalker profile image
Waylon Walker

Thanks for the great description Tyler. I had no idea how git bisect was used. It looks quite useful.

Collapse
 
thawkin3 profile image
Tyler Hawkins

You're welcome! Thanks for reading.

Collapse
 
cgood92 profile image
Clint Goodman

I come back to this post over and over and over again. Good reference guide to something I use often. Thanks!

Collapse
 
thawkin3 profile image
Tyler Hawkins

No prob!