Jacob
Jacob

Reputation: 4021

Get tag of latest git commit

I want to find the tag of the last commit if it is present. So far I have found only the option to get the last tag inside all of the tags..

But I want to know if there is a tag on the last commit or no tag?

Upvotes: 2

Views: 240

Answers (1)

LeGEC
LeGEC

Reputation: 51780

[edit] @phd pointed out that git tag has a --points-at option, which makes for a nicer command :

git tag --points-at HEAD

my initial answer :

You can use the --points-at option of git for-each-ref :

git for-each-ref --points-at=HEAD

To display only the tag name, and limit the searched refs to tag :

git for-each-ref --points-at=HEAD --format="%(refname:lstrip=2)" refs/tags

Upvotes: 3

Related Questions