paint-brush
Understanding Git-Bisect, i.e. Use Binary Search to Find the Change that Introduced a Bugby@fhinkel
3,464 reads
3,464 reads

Understanding Git-Bisect, i.e. Use Binary Search to Find the Change that Introduced a Bug

by Franziska HinkelmannOctober 18th, 2018
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Git is a powerful tool. Once you’ve mastered <code class="markup--code markup--p-code">commit</code> and <code class="markup--code markup--p-code">merge</code>, there are endless possibilities. A very useful one is <code class="markup--code markup--p-code"><a href="https://git-scm.com/docs/git-bisect" target="_blank">git-bisect</a></code>. It helps you find a commit that introduced a certain change in behavior.
featured image - Understanding Git-Bisect, i.e. Use Binary Search to Find the Change that Introduced a Bug
Franziska Hinkelmann HackerNoon profile picture

Git is a powerful tool. Once you’ve mastered commit and merge, there are endless possibilities. A very useful one is [git-bisect](https://git-scm.com/docs/git-bisect). It helps you find a commit that introduced a certain change in behavior.

We use git-bisect a lot in the Node.js project. The Node.js project has good continuous integration but some bugs are only discovered after a release. With git-bisect, it’s easy to find the bad commit.

Try it!

If you want to try out git-bisect, here is a demo repository. At some point, a bug was introduced as you can see by running npx mocha test1.js. Can you find the bad commit?

Use this repository to practice git bisect.

Automating git-bisect

Instead of testing each step manually, you can run git-bisect with a script. It will use the script at each step and automatically mark the commit, until it finds the first bad commit.