33

I have the SHA ID of a commit that I am interested in and would like to know how to find the first tag that contains it.

2

2 Answers 2

27

As previously stated, this can be done with git describe. In your particular case, however, you may find it more convenient to run git name-rev --tags --name-only <SHA>, which outputs exactly what you want. See git-name-rev(1).

18

git describe --contains "$committish" shows a reference to the commit built on a tag plus a ~$n ancestorhood count, so the following command shows the most recent tag that contains a commit:

git describe --contains "$committish" | sed 's/~.*//'

If there is no tag that contains this commit, git describe will fail. If you'd like to get the (abbreviated) committish instead, add the --always option.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.