How to get the latest tag name in current branch in Git?

前端 未结 24 2182
你的背包
你的背包 2020-11-22 17:04

What\'s the simplest way to get the most recent tag in Git?

git tag a HEAD
git tag b HEAD^^
git tag c HEAD^
git tag

output:



        
24条回答
  •  名媛妹妹
    2020-11-22 17:41

    If you need a one liner which gets the latest tag name (by tag date) on the current branch:

    git for-each-ref refs/tags --sort=-taggerdate --format=%(refname:short) --count=1 --points-at=HEAD
    

    We use this to set the version number in the setup.

    Output example:

    v1.0.0
    

    Works on Windows, too.

提交回复
热议问题