Show which git tag you are on?

前端 未结 6 2136
既然无缘
既然无缘 2020-12-07 06:46

I\'m having trouble finding out which tag is currently checked out.

When I do:

git checkout tag1
git branch

I can\'t seem to find

6条回答
  •  一向
    一向 (楼主)
    2020-12-07 07:48

    Edit: Jakub Narębski has more git-fu. The following much simpler command works perfectly:

    git describe --tags
    

    (Or without the --tags if you have checked out an annotated tag. My tag is lightweight, so I need the --tags.)

    original answer follows:

    git describe --exact-match --tags $(git log -n1 --pretty='%h')
    

    Someone with more git-fu may have a more elegant solution...

    This leverages the fact that git-log reports the log starting from what you've checked out. %h prints the abbreviated hash. Then git describe --exact-match --tags finds the tag (lightweight or annotated) that exactly matches that commit.

    The $() syntax above assumes you're using bash or similar.

提交回复
热议问题