获取提交的最新标记

Get most recent tag on a commit

我有一个工作流程,我想使用 git 标签通过我的管道推送发布。

git init
touch readme.md
git add .
git commit -m "com1"
git tag -a 1.0.0-rc.1 -m "t1"

touch xxx
git add .
git commit -m "com2"
git tag -a 1.0.0-alpha1 -m "t2"
git tag -a 1.0.0-rc1 -m "t2"
git tag -a 1.0.0 -m "r1"

我的日志看起来像:

commit 132fa7712234e0ea0ee72b55123d9fbfd7dbe75a (HEAD -> master, tag: 1.0.0-alpha1, tag: 1.0.0-rc1, tag: 1.0.0)
Author: Ryan 
Date:   Mon Nov 26 11:08:21 2018 +0000

com2

commit 97c10b1c203bc34f1234ba38e214c9f72cc4a03a (tag: 1.0.0-rc.1)
Author: Ryan 
Date:   Mon Nov 26 11:07:43 2018 +0000

com1

如何确保只返回最新的标签?

git describe <commit ID>

完成任务。

它 returns 此提交可访问的最新标记,然后如果该标记不在提交本身上,则附加所述提交的描述(提交数 "away" + 标记的提交 ID )

有关选项和详细信息,请参阅 documentation

或者,如果评论建议您尝试让此信息出现在 git 日志的输出中,请尝试选项 --decorate=full