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

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

    Not much mention of unannotated tags vs annotated ones here. 'describe' works on annotated tags and ignores unannotated ones.

    This is ugly but does the job requested and it will not find any tags on other branches (and not on the one specified in the command: master in the example below)

    The filtering should prob be optimized (consolidated), but again, this seems to the the job.

    git log  --decorate --tags master |grep '^commit'|grep 'tag:.*)$'|awk '{print $NF}'|sed 's/)$//'|head -n 1
    

    Critiques welcome as I am going now to put this to use :)

提交回复
热议问题