How can I list tags contained by a given branch, the opposite of:
git tag --contains <commit>
commit=$(git rev-parse $branch)
for tag in $(git tag)
git log --pretty=%H $tag | grep -q -E "^$commit$"
This might be close to what you want:
git log --simplify-by-decoration --decorate --pretty=oneline "$committish" | fgrep 'tag: '
But, the more common situation is to just find the most recent tag:
git describe --tags --abbrev=0 "$committish"
--tagswill search against lightweight tags, do not use it if you only want to consider annotated tags.
--abbrev=0if you want to also see the usual “number of ‘commits on top’ and abbreviated hash” suffix (e.g. v1.7.0-17-g7e5eb8).