justinhj
justinhj

Reputation: 11316

How to find which tag in a git repository contains a specific commit

Using a command as below I determine when a certain function first appears in a git repository.

git log -Sfoo

What I want to determine, is which tag this first shows up in.

So for example in the node.js repository there are tags for each release, so I would like to determine which release has function foo in it.

git log will give me the commit hash which I'd then like to use to find the first tag it appears in.

Thanks!

Upvotes: 3

Views: 101

Answers (1)

alex
alex

Reputation: 490657

You could use the pickaxe like you've done to find the commit, and then use...

git tag --contains <sha1>

I'm not sure of the order, but if it's the first, you can pipe it through head -1.

You could find it with one mangled command...

git tag --contains $(git log --format="%H" -1 -Sfoo) | head -1

Upvotes: 4

Related Questions