在Git中获取最新标签的最简单方法是什么?

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

输出:

a
b
c

我应该写一个脚本来获得每个标记的日期时间并比较它们吗?


当前回答

将输出的标签的最新标签提交跨所有分支

git describe --tags $(git rev-list --tags --max-count=1)

其他回答

为了只获取当前分支/以当前分支为前缀的标记名上的最新标记,我必须执行以下命令

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

主分支:

git checkout master

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

master-1448

部门自定义:

git checkout 9.4

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

9.4-6

我最后需要做的是增加并获得标签+1用于下一个标签。

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

您可以查看一下git describe,它所做的事情与您所要求的类似。

要获得最新的标签(后面的示例输出):

git describe --tags --abbrev=0   # 0.1.0-dev

要获得最近的标签,以及被标记对象顶部的额外提交数&更多:

git describe --tags              # 0.1.0-dev-93-g1416689

要获取最近的带注释的标签:

git describe --abbrev=0
git describe --abbrev=0 --tags

如果你没有看到latest标签,请确保在运行之前获取origin:

git remote update