简体   繁体   English

如何使用 git describe 匹配隐藏的 ref

[英]how to match a hidden ref using git describe

deriving version numbers from a git repository seems to be a good solution for matching version numbers, but my scenario is a bit different. 从 git 存储库派生版本号似乎是匹配版本号的一个很好的解决方案,但我的情况有点不同。

The version numbers I generate I'd like to create hidden refs for (so they don't make it to other clients by default).我生成的版本号我想为其创建隐藏的引用(因此默认情况下它们不会传递给其他客户端)。 I don't want the clients to see a bunch of version churn on their fetches.我不希望客户在他们的获取中看到一堆版本流失。

The problem is, --match only works for tags, even if you use the --all flag.问题是, --match 仅适用于标签,即使您使用 --all 标志。

Example:例子:

git update-ref refs/_v.master.0.1 c2897c8338e02b99644640f3afb829c04cb48439 git update-ref refs/_v.master.0.1 c2897c8338e02b99644640f3afb829c04cb48439

this creates the hidden ref这将创建隐藏的参考

git describe --all c2897c8338e02b99644640f3afb829c04cb48439 git describe --all c2897c8338e02b99644640f3afb829c04cb48439
_v.master.0.1 [this shows up] _v.master.0.1 [显示出来]

yet this doesn't return anything:但这不会返回任何内容:

git describe --match _v* --all c2897c8338e02b99644640f3afb829c04cb48439 git 描述 --match _v* --all c2897c8338e02b99644640f3afb829c04cb48439
fatal: No names found, cannot describe anything.致命:未找到名称,无法描述任何内容。

I see in the documentation that --match "Only consider tags matching the given glob(7) pattern", but that seems lame, matching should be applicable to any ref type assuming other modifiers (-all --tags, etc) limit the scope of the ref types.我在文档中看到 --match “只考虑匹配给定 glob(7) 模式的标签”,但这似乎很蹩脚,匹配应该适用于任何 ref 类型,假设其他修饰符(-all --tags 等)限制引用类型的范围。

Any other way for me to do this?我还有其他方法可以做到这一点吗? One way I thought of is to create tags on one client, and map them (at push and fetch time) to hidden refs to/from the origin, but that seems like a lot of extra work.我想到的一种方法是在一个客户端上创建标签,并将它们(在推送和获取时间)映射到来自/来自源的隐藏引用,但这似乎需要很多额外的工作。 Is the ref matching I mention above available from the API if not the client?如果不是客户端,我上面提到的 ref 匹配是否可以从 API 获得?

thanks in advance!提前致谢!

You will have to check that with Git 2.14.x/2.15 (Q4 2017)您必须使用 Git 2.14.x/2.15(2017 年第四季度)进行检查

" git describe --match <pattern> " has been taught to play well with the " --all " option. git describe --match <pattern> ”已被教导与“ --all ”选项配合得很好。

See commit 6d68b2a (20 Sep 2017) by Max Kirillov ( max630 ) .请参阅Max Kirillov ( max630 ) 提交的 6d68b2a (2017 年 9 月 20 日
(Merged by Junio C Hamano -- gitster -- in commit 8c1bc7c , 29 Sep 2017) (由Junio C gitster合并gitster 提交 8c1bc7c ,2017 年 9 月 29 日)

describe : teach --match to handle branches and remotes describe : 教--match处理分支和遥控器

When git describe uses --match , it matches only tags, basically ignoring the --all argument even when it is specified.git describe使用--match ,它只匹配标签,基本上忽略--all参数,即使它被指定。

Fix it by also matching branch name and $remote_name/$remote_branch_name , for remote-tracking references, with the specified patterns.通过匹配分支名称和$remote_name/$remote_branch_name来修复它,用于远程跟踪引用,具有指定的模式。
Update documentation accordingly and add tests.相应地更新文档并添加测试。

It also deals with negative patterns:它还处理负面模式:

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 :如果我们假设官方发布标签的形式为“ v* ”,并且预发布候选的名称中包含“ *rc* ”,我们现在可以找到第一个引入提交abcdef发布标签:

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

Note that Git 2.16.x/2.17 (Q1 2018) will restore the proper output for " git describe --all ".请注意,Git 2.16.x/2.17(2018 年第一季度)将为“ git describe --all ”恢复正确的输出。
See commit 1bba001 (11 Dec 2017) by Daniel Knittl-Frank ( knittl ) .请参阅Daniel Knittl-Frank ( knittl ) 的commit 1bba001 (2017 年 12 月 11 日
(Merged by Junio C Hamano -- gitster -- in commit fac64e0 , 23 Jan 2018) (由Junio C gitster合并-- gitster -- in commit fac64e0 ,2018 年 1 月 23 日)

describe : prepend " tags/ " when describing tags with embedded name describe : 在描述带有嵌入名称的标签时,在前面加上“ tags/

The man page of the " git describe " command explains the expected output when using the --all option, ie the full reference path is shown, including heads/ or tags/ prefix. git describe ”命令的手册页解释了使用--all选项时的预期输出,即显示完整的参考路径,包括heads/tags/前缀。

When 212945d ("Teach git-describe to verify annotated tag names before output", Feb 28, 2008, Git v1.5.5-rc0) made Git favor the embedded name of annotated tags, it accidentally changed the output format when the --all flag is given, only printing the tag's name without the prefix.212945d (“Teach git-describe to verify annotated tag names before output”,2008 年 2 月 28 日,Git v1.5.5-rc0)使 Git 偏爱带注释的标签的嵌入名称时,它不小心更改了输出格式时--all给出了标志,只打印没有前缀的标签名称。

Check if --all was specified and re-add the " tags/ " prefix for this special case to fix the regression.检查是否指定了--all并为此特殊情况重新添加“ tags/ ”前缀以修复回归。


When " git describe C " finds an annotated tag with tagname A to be the best name to explain commit C , and the tag is stored in a " wrong " place in the refs/tags hierarchy, eg refs/tags/B , the command gave a warning message but used A (not B ) to describe C .当“ git describe C ”发现带有标记名A的注释标记是解释提交C的最佳名称,并且该标记存储在refs/tags层次结构中的“ wrong ”位置时,例如refs/tags/B ,命令给出了警告信息,但使用A (不是B )来描述C
If C is exactly at the tag, the describe output would be " A ", but " git rev-parse A^0 " would not be equal as " git rev-parse C^0 ".如果C正好在标签上,则描述输出将是“ A ”,但“ git rev-parse A^0 ”将不等于“ git rev-parse C^0 ”。

The behavior of the command has been changed with Git 2.27 (Q2 2020), to use the "long" form ie A-0-gOBJECTNAME , which is correctly interpreted by rev-parse .该命令的行为已在 Git 2.27(2020 年第 2 季度)中进行了更改,以使用“长”形式,即A-0-gOBJECTNAME ,由rev-parse正确解释。

See commit ff165f0 (20 Feb 2020) by Junio C Hamano ( gitster ) .请参阅Junio C gitster ( gitster ) 提交的 ff165f0 (2020 年 2 月 20 日
(Merged by Junio C Hamano -- gitster -- in commit 0f0625a , 27 Mar 2020) (由Junio C gitster合并-- gitster -- in commit 0f0625a ,2020 年 3 月 27 日)

describe : force long format for a name based on a mislocated tag describe :基于错误定位的标签强制使用长格式的名称

Helped-by: Matheus Tavares帮助:马修斯·塔瓦雷斯
Helped-by: Jeff King帮助:杰夫·金

An annotated tag has two names :带注释的标签有两个名称

  • where it sits in the refs/tags hierarchy and它位于refs/tags层次结构中的位置和
  • the tagname recorded in the " tag " field in the object itself.记录在对象本身的“ tag ”字段中的tag

They usually should match.它们通常应该匹配。

Since 212945d4 ("Teach git describe to verify annotated tag names before output", 2008-02-28, Git v1.5.5-rc0 -- merge ), a commit described using an annotated tag bases its name on the tagname from the object.212945d4 (“Teach git describe to verify annotated tag names before output”, 2008-02-28, Git v1.5.5-rc0 -- merge )以来,使用带注释的标签描述的提交将其名称基于对象的标记名。

While this was a deliberate design decision to make it easier to converse about tags with others, even if the tags happen to be fetched to a different name than it was given by its creator, it had one downside.虽然这是一个深思熟虑的设计决定,目的是让与他人更容易地谈论标签,即使标签碰巧被提取到与其创建者给的名称不同的名称,它也有一个缺点。

The output from " git describe ", at least in the modern Git, should be usable as an object name to name the exact commit given to the " git describe " command. git describe ”的输出,至少在现代 Git 中,应该可以用作对象名称来命名给“ git describe ”命令的确切提交。

Using the tagname, when two names differ, breaks this property, when describing a commit that is directly pointed at by such a tag.在描述由此类标记直接指向的提交时,当两个名称不同时,使用标记名会破坏此属性。

An annotated tag Bob made as " v1.0 " may sit at " refs/tags/v1.0-bob " in the ref hierarchy, and output from " git describe v1.0-bob^0 " would say " v1.0 ", but there may not be any tag at " refs/tags/v1.0 " locally or there may be another tag that points at a different object.注释标签 Bob 制作为“ v1.0 ”可能位于ref层次结构中的“ refs/tags/v1.0-bob ”,并且“ git describe v1.0-bob^0 ”的输出会说“ v1.0 ”,但“ refs/tags/v1.0 ”本地可能没有任何标签,或者可能有另一个标签指向不同的对象。

Note that this won't be a problem if a commit being described is not directly pointed at by such a mislocated tag.请注意,如果所描述的提交不是由此类错误定位的标签直接指向的,则这不会成为问题。

In the example in the previous paragraph, describing a commit whose parent is v1.0-bob would result in " v1.0 " (ie the tagname taken from the tag object) followed by " -1-gXXXXX " where XXXXX is the abbreviated object name, and a string that ends with " -g " followed by a hexadecimal string is an object name for the object whose name begins with hexadecimal string (as long as it is unique), so it does not matter if the leading part is " v1.0 " or " v1.0-bob ".在上一段的示例中,描述父项为v1.0-bob的提交将导致“ v1.0 ”(即取自标记对象的标记名)后跟“ -1-gXXXXX ”,其中XXXXX是缩写对象名,以“ -g ”结尾的字符串是十六进制字符串开头的对象的对象名(只要是唯一的),所以前导部分是否为“ v1.0 ”或“ v1.0-bob ”。

Show the name in the long format, ie with " -0-gXXXXX " suffix, when the name we give is based on a mislocated annotated tag to ensure that the output can be used as the object name for the object originally given to the command to fix the issue.以长格式显示名称,即带有“ -0-gXXXXX ”后缀,当我们给出的名称是基于错误定位的注释标签时,以确保输出可以用作最初提供给命令的对象的对象名称解决问题。

While at it, remove an overly cautious dead code to protect against an annotated tag object without the tagname.在此过程中,删除过于谨慎的死代码以防止没有标记名的带注释的标记对象。

Such a tag is filtered out much earlier in the codeflow, and will not reach this part of the code.这样的标记在代码流中更早地被过滤掉,并且不会到达代码的这部分。

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

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