gpt4 book ai didi

git-tag - 相对于特定标签的 git 版本

转载 作者:行者123 更新时间:2023-12-04 04:53:45 25 4
gpt4 key购买 nike

我们在我们的代码库中使用了多个标签标识符。例如。 ABC-1.3.5.234 和 DEF-1.2.1.25。 describe 命令几乎可以满足我的需求:

git describe --long

ABC-1.3.5.234-33-deadbeef

但我真的很想知道与历史记录中最近的 DEF 标签相关的值。有没有办法指定我想使用哪个标签作为计算相对距离的基础?我可以使用正则表达式吗?

最佳答案

git describe man page很清楚:

If an exact match was not found, git describe will walk back through the commit history to locate an ancestor commit which has been tagged. The ancestor's tag will be output along with an abbreviation of the input committish's SHA-1.

If multiple tags were found during the walk then the tag which has the fewest commits different from the input committish will be selected and output.
Here fewest commits different is defined as the number of commits which would be shown by git log tag..input will be the smallest number of commits possible.

因此您可能必须编写一个脚本:

  • git describe
  • 获取找到的提交和 git describe 提交
  • 重复直到找到你要找的标签
  • 在该循环期间对找到的标记对象之上的所有额外提交数“n”求和
  • 构建并输出结果字符串:DEF-xxx-n-DEF_SHA1

自 2013 年以来,如 Hendrik 中所示的 answer ,这个效果更好:

git describe --all --match <tagPattern>

但前提是,如我在“how to match a hidden ref using git describe”中所述,您使用的是 Git 2.15(2017 年第三季度)。
在 2.15 之前,--all 将被忽略。

注意:Git 2.15 也是 allows multiple patterns对于 git describe --match

这允许更高级的搜索,例如:

For example, suppose you wish to find the first official release tag that contains a certain commit.
If we assume that official release tags are of the form "v*" and pre-release candidates include "*rc*" in their name, we can now find the first release tag that introduces the commit abcdef:

git describe --contains --match="v*" --exclude="*rc*" abcd

关于git-tag - 相对于特定标签的 git 版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17056584/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com