Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
    
Does this answer your question? stackoverflow.com/questions/1474115/… –  jasonwryan Sep 9 '12 at 23:55
    
Awesome, yes. Thanks a lot! –  merryman Sep 10 '12 at 0:06

1 Answer 1

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.