Read more

git: find the version of a gem that releases a certain commit

Daniel Straßner
February 20, 2023Software engineer at makandra GmbH

Sometimes I ran across a GitHub merge request of a gem where it was not completely obvious in which version the change was released. This might be the case for a bugfix PR that you want to add to your project.

Illustration online protection

Rails professionals since 2007

Our laser focus on a single technology has made us a leader in this space. Need help?

  • We build a solid first version of your product
  • We train your development team
  • We rescue your project in trouble
Read more Show archive.org snapshot

Git can help you to find the next git tag that was set in the branch. This usually has the name of the version in it (as the rake release task automatically creates a git tag during release).

git name-rev --tags <commit ref>

Note

The more commonly used git describe command will return the last tag before a commit, git name-rev the next tag after the commit:

$ git describe 54a28b1
v6.1.4.6-104-g54a28b18b4

$ git name-rev --tags 54a28b1
54a28b1 tags/v6.1.5~8

Example

Here is a simplified example to showcase this:

f5ef0dc o │ │ Make sure allowed image processing arguments are correctly loaded
5341053 o─┴─┘ <v6.1.5> Preparing for 6.1.5 release     <=== this releases the commit we need
c67e8d8 o Merge pull request #44641 from SkipKayhil/fix-rubocop-errors
1afe117 o Update CHANGELOG [ci skip]
87528db o Revert "Merge pull request #43209 from mpestov/check-basic-auth-credentials"
b10c0ff M─┐ Merge branch '6-1-sec' into 6-1-stable
6607333 │ o <v6.1.4.7> Preparing for 6.1.4.7 release
1f66424 │ o bumping version
b0b5eaf │ o Added image trasnformation validation via configurable allow-list
13cdd7a o │ Fix typo in net-smtp error check
a12ba30 M─│─┐ Merge pull request #44600 from rails/rm-handle-mail-in-3.1
06ac69f │ │ o Handle net-smtp mail dependency error for Ruby 3.1
97064aa o─│─┘ Fix logger format with Ruby 3.1
54a28b1 o │ Support dalli 3.2.1                       <=== we need this commit
bd5188b o │ Fix flakey Memcache tests
...
923d91e M─│─┐ Merge branch '6-1-sec' into 6-1-stable
10a2c77 │ o─┘ <v6.1.4.6> Preparing for 6.1.4.6 release

Imagine, we're looking for the release that adds support for dalli 3.2.1. The commit sha is 54a28b1. We can ask git to give the name of this commit in relation to the next tag assigned:

$ git name-rev --tags 54a28b1
54a28b1 tags/v6.1.5~8

The gem release we're looking for is 6.1.5. The rest of the string ~8 means, that the dalli commit is 8 commits before the gem release.

From the example git log it's still relatively easy to see, which version was released after the commit, but a git log might be a lot longer and a lot more complicated.

Posted by Daniel Straßner to makandra dev (2023-02-20 13:34)