简体   繁体   English

如何获取最新版本的git标签以及到HEAD的距离

[英]How to get the latest release tag in git and the distance to HEAD

Using https://github.com/google/glog as an example. https://github.com/google/glog为例。 The latest release is 0.3.5. 最新版本是0.3.5。

After searching hours on stackoverflow and google, I am not able to find a correct answer. 在stackoverflow和Google上搜索了几个小时后,我找不到正确的答案。

git describe 

shows 节目

v0.3.3-147-gb3695ee

and

git describe --tags

shows 节目

v0.3.4-133-gb3695ee

and

git describe --tags `git rev-list --tags --max-count=1`

shows 节目

v0.3.5

What command should I type in order to get 我应该输入什么命令才能获得

v0.3.5-41-gb3695ee

I think your command use is correct, and it's more of a repo/branch issue. 我认为您的命令使用是正确的,更多的是回购/分支问题。

Briefly, from the describe documentation: 简要地,从describe文档中:

The command finds the most recent tag that is reachable from a commit. 该命令查找可从提交访问的最新标记。 If the tag points to the commit, then only the tag is shown. 如果标签指向提交,则仅显示标签。 Otherwise, it suffixes the tag name with the number of additional commits on top of the tagged object and the abbreviated object name of the most recent commit. 否则,它将在标记名称后加上标记对象后附加的提交次数以及最近提交的缩写对象名称后缀。

By default (without --all or --tags) git describe only shows annotated tags. 默认情况下(不带--all或--tags),git describe只显示带注释的标签。 For more information about creating annotated tags see the -a and -s options to git-tag. 有关创建带注释标签的更多信息,请参见git-tag的-a和-s选项。

So if the desired tag isn't being shown using git describe , we can assume it's either: 因此,如果没有使用git describe来显示所需的标签,我们可以假设是:

  • Not reachable from the current commit. 从当前提交无法访问。
  • Not an annotated tag. 不是带注释的标签。
  • Not an existing tag. 没有现有标签。

To show non-annotated tags, we can used git describe --tags . 为了显示非注释标签,我们可以使用git describe --tags Since this seems to give us a different tag, but not the one you're after, we can probably conclude that the tag you're interested in either doesn't exist, or is not reachable from the current branch. 由于这似乎为我们提供了一个不同的标签,但没有给您提供一个标签,因此我们可以得出结论,您感兴趣的标签不存在,或者无法从当前分支访问。

I cloned the repo in question and ran git tag --list which does show a selection of tags including 0.3.3 , 0.3.4 , and 0.3.5 . 我克隆问题的回购,跑git tag --list这确实显示出选择的标签,包括0.3.30.3.40.3.5 So it seems the tag exists, but must not be on the master branch. 因此,该标签似乎已存在,但不能位于master分支上。 We can confirm this with git branch --contains <commit> , where <commit> will be 0.3.5 . 我们可以使用git branch --contains <commit>确认这一点,其中<commit>0.3.5 If you haven't yet cloned any remote branches, this will give you no results. 如果您尚未克隆任何远程分支,则将没有任何结果。

We can run git branch -r --contains <commit> to check the remote branches, which gives the output origin/v035 . 我们可以运行git branch -r --contains <commit>来检查远程分支,它给出了输出origin/v035 It looks like the tag we're after is only reachable on the remote origin/v035 branch. 看起来我们所需要的标签只能在远程origin/v035分支上访问。

If we checkout this branch locally, and run git describe --tags , we will get the output v0.3.5 , we don't see the suffix described by the docs, because the tag points at the current commit (tip of the branch). 如果我们在本地检出此分支,然后运行git describe --tags ,将获得输出v0.3.5 ,我们看不到文档描述的后缀,因为该标记指向当前提交(分支的尖端) 。

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

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