I have a rather large git repository with files that have been left unchanged for years. As such they have been part of many commits, and some of these commits have been tagged (published versions).
How can I obtain a list of all the tags that contain a specific version of the file (the currently checked out version for instance). All the commands I see only list commits where the file has changed, while I am interested in all the ones after that change.
(this question is similar to this one but for Git...)
CodePudding user response:
git for-each-ref refs/tags \
--format=$'%(objectname)^{commit}:path/to/that/file\t%(refname:short)' \
| git cat-file --batch-check=$'%(objectname)\t%(rest)' --buffer \
| awk '$1==id { print $2 }' id=`git rev-parse :path/to/that/file`
for the currently-checked-out version you mentioned, otherwise put some commit identifier in front of the :
on the last line.
The f-e-r formats a revision syntax specifier for that file's object name in each tag's commit, the git cat-file --batch-check
looks up the object and if it exists prints its id and the rest of the line, here the tag's short name; the awk picks out the ones you want.
CodePudding user response:
git tag --contains [<commit>]
If you specify the optional <commit>
argument, that commit will be used, otherwise the current HEAD
will be used.