When I do a git log filename
or some listing of the commits that a file has been through, I'd like to see all the tags that were applied to the repository where the file was exactly the version specified in the git log filename
. Is this possible?
1 Answer
First, figure out the commit hash of the commit you are interested in -- in this example it is 6502bcc16b3790cc22cb771d1da3e8f35b4009c0:
$ git log «filename»
commit 6502bcc16b3790cc22cb771d1da3e8f35b4009c0
Author: Mike Morearty <[email protected]>
Date: Wed Jun 13 16:04:56 2012
added «filename»
Then, use git tag --contains
to ask for all tags that contain that commit:
$ git tag --contains 6502bcc16b3790cc22cb771d1da3e8f35b4009c0
tag1
tag2
If you want to do all of that in one line, here is one way (perhaps there are more efficient ways):
$ git tag --contains $(git log -1 --pretty=%H «filename»)
-
Excellent. I didn't know about
--contains
. If I wanted to inline the tags in the complete log of the file, would I do something like this?git log filename | perl -ne 'print $_; if (m/^commit (.*)/) { print "tags: ".`git tag --contains $1`;}'
Commented Jun 13, 2012 at 23:41 -
1Yeah, something like that. Another thing you might like is adding
[log] decorate = true
to your.gitconfig
. It adds tag and branch names to allgit log
commands (but not all tags, only ones that are at that exact spot). Commented Jun 13, 2012 at 23:58