简体   繁体   English

使用 git 描述从 git 获取最新的主标签版本

[英]Getting the latest main tag version from git using git describe

I have lot of tags for candidate and dev like:我有很多候选人和开发人员的标签,例如:

  • 1.1.1-dev.2 1.1.1-dev.2
  • 1.1.2-rc.0 1.1.2-rc.0

i would like to get the last main tag in git that match to production semver我想获得 git 中与生产 semver 匹配的最后一个主标签

for example: for version 1.1.2-rc.0例如:对于版本 1.1.2-rc.0

i will get the last production tag that was 1.1.1我将获得最后一个生产标签,即1.1.1

i was trying the following:我正在尝试以下操作:

git describe --tags --abbrev=1 
 git describe  --abbrev=0  | awk -F - '{print $1}'

will give me 1.1.2 but there is no tag like that会给我 1.1.2 但没有这样的标签

i would like to get the last main tag in git that match to production semver我想获得 git 中与生产 semver 匹配的最后一个主标签

Tags, in Git, are not on branches. Git 中的标签不在分支上。 They are on commits.他们正在提交。 So "main tag" does not seem to mean anything.所以“主要标签”似乎没有任何意义。

 git describe --abbrev=0 | awk -F - '{print $1}'

will give me 1.1.2 but there is no tag like that会给我 1.1.2 但没有这样的标签

Of course: you told awk to treat - as a field separator, so that 1.1.2-rc.0 was treated as two fields containing 1.1.2 and rc.0 : those are the two strings that are separated by the - character.当然:您告诉awk-视为字段分隔符,因此1.1.2-rc.0被视为包含1.1.2rc.0的两个字段:它们是由-字符分隔的两个字符串。 Then you told awk to print the first field, ignoring the second one entirely, and it did exactly what you asked.然后你告诉awk打印第一个字段,完全忽略第二个字段,它完全按照你的要求做了。

The git describe command here may be the wrong tool to use.此处的git describe命令可能是使用错误的工具。 It's not clear what the right tool would be, as it's not clear from your question what tag you want based on the specific commit.目前尚不清楚正确的工具是什么,因为从您的问题中不清楚根据特定提交您想要什么标签。 However, if what you want is:但是,如果您想要的是:

  • the git describe tag if it does not end with -rc* (glob syntax), or git describe标签,如果它-rc* (全局语法)结尾,或者
  • the git describe tag converted to a three-part number, minus 1, if it does end with rc* git describe标签转换为三部分数字,减 1,如果它确实rc*结尾

then you can do that with git describe .然后你可以用git describe来做到这一点。 The problem with this is likely to occur at boundaries: if you're on 1.1.2-rc0 it's pretty clear that the previous version would be 1.1.1 , but if you're on 1.1.0-rc3 for instance, is the previous version 1.0.0 , 1.0.19`, or what?这个问题很可能发生在边界上:如果你在1.1.2-rc0上,很明显以前的版本是1.1.1 ,但如果你在1.1.0-rc3上,例如以前的版本 1.0.0 , 1.0.19`,还是什么? What does previous version mean in this context?在这种情况下,以前的版本意味着什么? Why do you need a "previous version" in the first place?为什么首先需要“以前的版本”?

You may need to write a program to compute the answer you want, depending on what the question is.您可能需要编写一个程序来计算您想要的答案,具体取决于问题是什么。 You'll need to figure out your precise question first.您需要先弄清楚您的确切问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM