简体   繁体   English

如何在独立的head commit上使用git describe?

[英]How to use git describe on a detached head commit?

I have a main branch that has annotated-non-lightweight-tagged commits in it. 我有一个主分支,其中有带注释的非轻量标记的提交。 The workspace is in a detached head state, ie after checked out via Jenkins Multibranch Pipeline 工作空间处于分离状态,即通过Jenkins Multibranch Pipeline检出后

When I run git describe I am getting the name of a really old tag, together with a very high number of commits since that tag, (eg 1.0.0-459-abc1234 ) 当我运行git describe我得到的是一个非常旧的标签的名称,以及自该标签以来的大量提交(例如1.0.0-459-abc1234

When I run git tag I get a list of all tags, including the most recent ones, that I am interested in, eg 3.1.0 , 3.2.0 . 当我运行git tag我得到的所有标签的列表,包括最近的,我很感兴趣,例如3.1.03.2.0

I was then thinking about doing something like git branch -r --contains HEAD to get the name of the remote branch, then fetch and check that out (Running the risk that I am actually checking out a later commit than the one that triggered the pipeline, but whatever, it's isolated to a pull request anyways...) Or just run git describe <remote_branch_name> But neither of that worked. 然后我正在考虑做类似git branch -r --contains HEAD来获取远程分支的名称,然后获取并签出(冒着我实际签出比触发了提交的提交晚的风险。管道,但是无论如何,无论如何,它都是与拉取请求隔离的……)或者只是运行git describe <remote_branch_name>但这两个都git describe <remote_branch_name> I don't understand why Git would prefer to show the very old tag instead of more recent ones, since any pull request is branched off the tag-containing master branch (every commit that had been tagged is guaranteed to be found on the master branch). 我不明白为什么Git宁愿显示非常老的标签而不是最近的标签,因为任何拉取请求都是从包含标签的master分支分支出来的(保证已标记的每个提交都可以在master分支上找到) )。

The reason for the problem might have been different git version actually. 问题的原因可能实际上是git版本不同。 One host had a rather old git version installed (1.7.x) after upgrading to 2.10.x everywhere, the problem went away. 一台主机到处升级到2.10.x之后,安装了一个相当旧的git版本(1.7.x),问题消失了。 Another possible reason could be that we sometimes updated tags, pointing them to a new commit (we stopped doing that.) I noticed at one point, that when you create a lightweight tag, and then change it to a annotated tag, another client that had already seen the lightweight tag, will not download the updated, now annotated tag, when you do git fetch --tags , because it recognizes it had already seen the tag by name, and does not bother that the type of the tag has changed, therefore git describe will not pick up that tag for that client. 另一个可能的原因可能是我们有时会更新标签,将它们指向一个新的提交(我们停止这样做。)我注意到,有一点是,当您创建一个轻量级标签,然后将其更改为带注释的标签时,另一个客户端git fetch --tags ,已经看到了轻量级标签,将不会下载更新的,现在带注释的标签,因为它可以识别出已经按名称看到了标签,并且不会担心标签的类型已更改,因此git describe不会为该客户端选择该标签。

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

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