git 如何获取最新的标签名称?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4277773/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 09:32:47  来源:igfitidea点击:

How to get latest tag name?

git

提问by VeroLom

How to get latest tag name (like version) of current branch?

如何获取当前分支的最新标签名称(如版本)?

回答by VonC

git describeshould be enough

git describe应该够了

The command finds the most recent tag that is reachable from a commit.
If the tag points to the commit, then only the tag is shown.
Otherwise, it suffixes the tag name with the number of additional commits on top of the tagged object and the abbreviated object name of the most recent commit.

With --abbrevset to 0, the command can be used to find the closest tagname without any suffix:

该命令查找可从提交中访问的最新标记。
如果标记指向提交,则仅显示标记。
否则,它将在标记对象之上附加提交的数量和最近提交的缩写对象名称作为标记名称的后缀。

随着--abbrev设置为0,该命令可以用来查找不带任何后缀最接近的标记名

[torvalds@g5 git]$ git describe --abbrev=0 v1.0.5^2
tags/v1.0.0

For tags matching a certain pattern:

对于匹配特定模式的标签:

git describe --tags --abbrev=0 --match release-*

(Peterino's comment)

彼得里诺评论

For the latest tag on allthe branches (not just the latest branch)

对于所有分支上的最新标签(不仅仅是最新的分支)

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

(from kilianc's answer)

(来自kilianc回答