Announcing git bisect-find
Tags: git, tools
Published: 2024-04-20 16:36:51

---
title: Announcing git bisect-find
published: true
date: 2024-04-19 16:50:00 UTC
tags: Git,Tools
canonical_url: https://kevincox.ca/2024/04/19/git-bisect-find/
---

<main style="--gap:1em;display:grid;gap:var(--gap);grid:none/1fr minmax(0,36em) 1fr;overflow:auto;padding:0;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><p style="box-sizing:border-box;grid-column:2;margin:0">This is a small utility that I wrote to compliment <a href="https://git-scm.com/docs/git-bisect" style="box-sizing:border-box;margin:0;text-decoration:underline;-webkit-text-decoration-color:gray;text-decoration-color:gray"><code style="background:#000;border:1px solid #555;border-radius:.3em;box-sizing:border-box;color:#fff;margin:0;padding:0 .2em;white-space:pre-wrap">git bisect</code></a>. <code style="background:#000;border:1px solid #555;border-radius:.3em;box-sizing:border-box;color:#fff;margin:0;padding:0 .2em;white-space:pre-wrap">git bisect</code> is a fantastic tool. In the most basic usage you give it one “good” commit (a commit that doesn’t yet include some property) and at least one “bad” commit (one that does have it). <code style="background:#000;border:1px solid #555;border-radius:.3em;box-sizing:border-box;color:#fff;margin:0;padding:0 .2em;white-space:pre-wrap">git bisect</code> will then guide you through the search, picking commits to test that cut the search space in half. This allows you to efficiently identify the first commit with a particular feature.</p>
<p style="box-sizing:border-box;grid-column:2;margin:0">However one of the premises of <code style="background:#000;border:1px solid #555;border-radius:.3em;box-sizing:border-box;color:#fff;margin:0;padding:0 .2em;white-space:pre-wrap">git bisect</code> is that you know a good commit. Often times you notice a bug but don’t yet know a good version. Was that broken in the last release? Or is it new? Maybe it was broken unnoticed in the past couple of releases? Sure, you could start checking out various revisions to see if the bug is there, but why do this manually?</p>
<p style="box-sizing:border-box;grid-column:2;margin:0">This is where <a href="https://gitlab.com/kevincox/git-bisect-find" style="box-sizing:border-box;margin:0;text-decoration:underline;-webkit-text-decoration-color:gray;text-decoration-color:gray"><code style="background:#000;border:1px solid #555;border-radius:.3em;box-sizing:border-box;color:#fff;margin:0;padding:0 .2em;white-space:pre-wrap">git bitsect-find</code></a> comes in. It will take just a bad commit, and step back looking for the first good commit. Basic usage looks like this:</p>
<h2 id="basic-usage" style="box-sizing:border-box;grid-column:2;margin:.4em 0 0"><a href="https://kevincox.ca/2024/04/19/git-bisect-find/#basic-usage" style="box-sizing:border-box;color:inherit!important;margin:0;text-decoration:inherit;text-decoration:underline;-webkit-text-decoration-color:gray;text-decoration-color:gray;text-shadow:inherit!important">Basic Usage</a></h2>
<p style="box-sizing:border-box;grid-column:2;margin:0">First check out your bad commit:</p>
<div style="background:#222;border-color:#444;border-style:solid;border-width:1px 0;box-sizing:border-box;display:grid;grid-column:2;grid-column:1/4;grid-template-columns:subgrid;margin:0;overflow-x:auto;padding:0"><pre style="box-sizing:border-box;grid-column:2;line-height:1;margin:.4em 0"><code style="background:none!important;box-sizing:border-box;color:#fff;margin:0;white-space:pre-wrap;white-space:pre"><span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">$ </span>git checkout main
</code></pre></div>
<p style="box-sizing:border-box;grid-column:2;margin:0">Then start bisecting with <code style="background:#000;border:1px solid #555;border-radius:.3em;box-sizing:border-box;color:#fff;margin:0;padding:0 .2em;white-space:pre-wrap">git bisect-find bad</code>.</p>
<p style="box-sizing:border-box;grid-column:2;margin:0">You will be asked to start a regular <code style="background:#000;border:1px solid #555;border-radius:.3em;box-sizing:border-box;color:#fff;margin:0;padding:0 .2em;white-space:pre-wrap">git bisect</code> run, type <kbd style="border:2px solid #555;border-radius:2px;box-shadow:2px 2px #333;box-sizing:border-box;margin:0;padding:0 .1em">y</kbd>.</p>
<p style="box-sizing:border-box;grid-column:2;margin:0">Then a new candidate commit will be checked out. If the candidate commit is bad run <code style="background:#000;border:1px solid #555;border-radius:.3em;box-sizing:border-box;color:#fff;margin:0;padding:0 .2em;white-space:pre-wrap">git bisect-find bad</code> and a new candidate will be checked out. Repeat the test and mark process until a good commit is found.</p>
<p style="box-sizing:border-box;grid-column:2;margin:0">Once you have a good commit found you are done with <code style="background:#000;border:1px solid #555;border-radius:.3em;box-sizing:border-box;color:#fff;margin:0;padding:0 .2em;white-space:pre-wrap">git bisect-find</code>. Just run <code style="background:#000;border:1px solid #555;border-radius:.3em;box-sizing:border-box;color:#fff;margin:0;padding:0 .2em;white-space:pre-wrap">git bisect good</code> and continue with the regular bisection process.</p>
<h2 id="more" style="box-sizing:border-box;grid-column:2;margin:.4em 0 0"><a href="https://kevincox.ca/2024/04/19/git-bisect-find/#more" style="box-sizing:border-box;color:inherit!important;margin:0;text-decoration:inherit;text-decoration:underline;-webkit-text-decoration-color:gray;text-decoration-color:gray;text-shadow:inherit!important">More</a></h2>
<p style="box-sizing:border-box;grid-column:2;margin:0">There are more complete docs <a href="https://gitlab.com/kevincox/git-bisect-find/-/blob/master/README.md" style="box-sizing:border-box;margin:0;text-decoration:underline;-webkit-text-decoration-color:gray;text-decoration-color:gray">in the README</a>. There are also more features to add (like automatic bisection). However the basics have already been quite useful to me so I figured I would share.</p>
<h2 id="mechanism" style="box-sizing:border-box;grid-column:2;margin:.4em 0 0"><a href="https://kevincox.ca/2024/04/19/git-bisect-find/#mechanism" style="box-sizing:border-box;color:inherit!important;margin:0;text-decoration:inherit;text-decoration:underline;-webkit-text-decoration-color:gray;text-decoration-color:gray;text-shadow:inherit!important">Mechanism</a></h2>
<p style="box-sizing:border-box;grid-column:2;margin:0">There really isn’t anything too special about the way it works. It just jumps back twice as far each time (following first parents). All state is logged via regular <code style="background:#000;border:1px solid #555;border-radius:.3em;box-sizing:border-box;color:#fff;margin:0;padding:0 .2em;white-space:pre-wrap">git bisect</code> so once you find a good commit all of your <code style="background:#000;border:1px solid #555;border-radius:.3em;box-sizing:border-box;color:#fff;margin:0;padding:0 .2em;white-space:pre-wrap">git bisect-find bad</code> (and <code style="background:#000;border:1px solid #555;border-radius:.3em;box-sizing:border-box;color:#fff;margin:0;padding:0 .2em;white-space:pre-wrap">git bisect-find skip</code>) commands are remembered as regular <code style="background:#000;border:1px solid #555;border-radius:.3em;box-sizing:border-box;color:#fff;margin:0;padding:0 .2em;white-space:pre-wrap">git bisect bad</code> and <code style="background:#000;border:1px solid #555;border-radius:.3em;box-sizing:border-box;color:#fff;margin:0;padding:0 .2em;white-space:pre-wrap">git bisect skip</code> would be.</p>
<p style="box-sizing:border-box;grid-column:2;margin:0">I do wonder if jumping back by twice as much is optimal. Obviously jumping right to the first commit would reduce the number of <code style="background:#000;border:1px solid #555;border-radius:.3em;box-sizing:border-box;color:#fff;margin:0;padding:0 .2em;white-space:pre-wrap">git bisect-find</code> steps. But would result in more <code style="background:#000;border:1px solid #555;border-radius:.3em;box-sizing:border-box;color:#fff;margin:0;padding:0 .2em;white-space:pre-wrap">git bisect</code>. But <code style="background:#000;border:1px solid #555;border-radius:.3em;box-sizing:border-box;color:#fff;margin:0;padding:0 .2em;white-space:pre-wrap">git bisect</code> is quite efficient. (Not to mention that the first commit is likely not particularly interesting.) At some point I should probably work out which growth pattern results in the shortest number of total steps. However I think the optimal number also depends on the distribution of the age of the target commit. But either way doubling works well enough for this tool to be very helpful for me.</p></main>