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

前端 未结 24 2169
你的背包
你的背包 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:16

    To get the latest tag only on the current branch/tag name that prefixes with current branch, I had to execute the following

    BRANCH=`git rev-parse --abbrev-ref HEAD` && git describe --tags --abbrev=0 $BRANCH^ | grep $BRANCH
    

    Branch master:

    git checkout master
    
    BRANCH=`git rev-parse --abbrev-ref HEAD` && git describe --tags 
    --abbrev=0 $BRANCH^ | grep $BRANCH
    
    master-1448
    

    Branch custom:

    git checkout 9.4
    
    BRANCH=`git rev-parse --abbrev-ref HEAD` && git describe --tags 
    --abbrev=0 $BRANCH^ | grep $BRANCH
    
    9.4-6
    

    And my final need to increment and get the tag +1 for next tagging.

    BRANCH=`git rev-parse --abbrev-ref HEAD` && git describe --tags  --abbrev=0 $BRANCH^ | grep $BRANCH | awk -F- '{print $NF}'
    

提交回复
热议问题