A (Brief!) Intro to Git Bisect

Doug Price / @solipet

a beautifully drawn frog, very realistic actually

January 10, 2017

Git Bisect

Use binary search to find the commit
that introduced a change

Basic Usage

``` bash $ git bisect start $ git bisect bad $ git checkout last-known-working-tag $ git bisect good ```

Pick your own terms

If "good" and "bad" don't fit the search you are doing, use different terms.

``` bash $ git bisect start --term-new foo --term-old bar $ git bisect foo $ git bisect bar last-known-bar-tag ```

Don't be so judgy!

If "good" and "bad" are too judgemental for you, pick terms you like.

``` bash $ git bisect start --term-new a-for-effort --term-old solid $ git bisect a-for-effort $ git bisect solid last-known-solid-tag ```

Or perhaps you're looking for a regression in performance...

``` bash $ git bisect start --term-new slow --term-old fast $ git bisect slow $ git bisect fast last-known-fast-tag ```

Or maybe you just noticed that things got way better and you want to know how/why/thanks to whom...

``` bash $ git bisect start --term-new amazing --term-old meh $ git bisect amazing $ git bisect meh last-known-meh-tag ```

Oops! I meant good, not bad!

No problem! Just recode the bisect to a file, reset it, then edit the file and replay it!

``` bash $ git bisect bad $ git bisect log > bisect_log # edit bisect_log to git rid of bad call $ git bisect reset $ git bisect replay bisect_log ```

Ugh! This commit is so f'd I can't even test it!!

No problem -- just skip it.

``` bash $ git bisect skip ```

Or, if you know you're close to a commit that you can test, check it out!

``` bash $ git bisect good/bad # previous round was good or bad. Bisecting: 337 revisions left to test after this (roughly 9 steps) $ git reset --hard HEAD~3 # try 3 revisions before what # was suggested $ git bisect good/bad ```

OK, that was fun the first time...

If your test can be automated with a script, then the entire bisect can be automated!

``` bash $ git bisect run test_script.sh arguments ```

Let's give it a try!

via GIPHY

References

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

(It's all right here! ^^^)