Using Git Bisect and Other Commands to Determine When Something Was Removed

Quickly Sleuthing through a Code Base

On I was tasked with upgrading a User Interface (UI 📖) dependency for a Hyku 📖 application. To get to a suitable newer version I needed to replace the Ruby gem (that used Bower) with a Yarn package. The Ruby gem had been deprecated.

In the project’s fork of Hyku they had the following pul_uv_rails in the Gemfile.lock. I needed to know when that went away in the upstream savmera/hyku repository ; because that would provide guidance on how to perform the update.

From the upstream Hyku project I checked out the commit that best represented the current state of the project I was working on. I looked in the Gemfile.lock and found pul_uv_rails. That commit was 7db4497.

I then fired up git bisect; with bisect you provide three things, the good commit, the bad commit, and the test.

The test is a shell command that exits 0 for a “good” status and not 0 (e.g. 1) for a “bad” status. The provide “good” and “bad” commits are the boundaries of the commits you’ll check.

With those three things, git bisect finds the commit that flips the shell commands exit status from 0 to not 0. In other words, when does the repository go from a “good” to a “bad” state.

For this example, I then ran the following:

git bisect start
Start the bisect process.
git bisect good 7db4497
Specify the “good” commit’s Secure Hash Algorithm (SHA 📖).
git bisect bad main
Specify a known “bad” commit.
git bisect run rg pul_uv_rails Gemfile.lock
Run `rg pul_uv_rails Gemfile.lock`; search the `Gemfile.lock` for the presence of `pul_uv_rails`.

In about 7 passes, it found that 0a6d04716727c10efc0ce5f1fbafef99f363e041 was the commit that removed pul_uv_rails from the Gemfile.lock. Now I could look at that commit and see the contextual change.

Which pointed to upgrading Hyrax from v2.9.6 to v3.0.0. The pul_uv_rails gem was a secondary dependency that came from Hyrax.

Hoping over to Hyrax, I wanted to see the more narrow commit that removed the pul_uv_rails.

This time I ran the following:

git bisect start
Start bisect
git bisect good 426575a90
the SHA for v2.9.6 of Hyrax.
git bisect bad main
a known point that didn’t have `pul_uv_rails`
git bisect run rg pul_uv_rails hyrax.gemspec
Test the gemspec file for presence of `pul_uv_rails`

I found the answer: commit de959fa6.

Out of curiosity, I wanted to see what all tagged versions had this. So I ran the following: git tag --contains de959fa6.

Which produced the following results:


Interesting, someone had back-ported the fix to v2.5.2 but not v2.9.x or later. Something to consider.