【问题标题】:Get last git tag matching string获取最后一个 git 标签匹配字符串
【发布时间】:2014-11-14 00:06:55
【问题描述】:

在 git 中,假设我有多个带有修订号的标签,例如:

v1.1.0
v1.2.0
v1.2.1
v1.2.3

我有兴趣从标签中获取最后一个版本号。如果我这样做了

git describe --tags --match "v1.2.*"

我会得到v1.2.0 作为结果,但我真的想要v1.2.3

【问题讨论】:

  • git describe 用于查找可以从 HEAD 访问的标签。这听起来更像是您只想列出标签然后对它们进行排序?

标签: git tagging


【解决方案1】:

如果你想列出所有标签,使用特定的顺序,你可以(使用 git 2.0+)使用排序选项。
见“How to sort git tags?

git tag -l --sort=refname "v1.2.*"
# or (note the '-' sign in '-version' to reverse the order)
git tag -l --sort=-version:refname "v1.2.*"  

在每种情况下,first 结果应该是 v1.2.3

【讨论】:

【解决方案2】:

也可以使用 git describe

git describe --tags --match "v1.2.*" $(git rev-list --tags --max-count=1)

帮助:https://stackoverflow.com/a/30811684/3598880

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-25
    • 1970-01-01
    • 2011-04-21
    • 1970-01-01
    • 1970-01-01
    • 2018-10-27
    • 1970-01-01
    相关资源
    最近更新 更多