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
How to get latest tag name?
提问by VeroLom
How to get latest tag name (like version) of current branch?
如何获取当前分支的最新标签名称(如版本)?
回答by VonC
git describe
should 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
--abbrev
set 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-*
For the latest tag on allthe branches (not just the latest branch)
对于所有分支上的最新标签(不仅仅是最新的分支)
git describe --tags $(git rev-list --tags --max-count=1)