简体   繁体   English

“git describe”忽略标签

[英]“git describe” ignores a tag

In the following lines:在以下几行中:

$ git tag -n1
v1.8        Tagged the day before yesterday
v1.9        Tagged yesterday
v2.0        Tagged today
$ git describe
v1.9-500-ga6a8c67
$ 

Can anyone explain why the v2.0 tag is not used by "git describe", and how to fix this?谁能解释为什么“git describe”不使用 v2.0 标签,以及如何解决这个问题? The v2.0 tag is already pushed, so I am guessing that I can't just delete and re-add it. v2.0 标签已经推送了,所以我猜我不能只是删除并重新添加它。

git describe uses only annotated tags by default. git describe默认情况下只使用带注释的标签。 Specify the --tags option to make it use lightweight tags as well.指定--tags选项以使其也使用轻量级标签。

Make sure you've checked out the correct commit ( git rev-parse HEAD ).确保您已检出正确的提交 ( git rev-parse HEAD )。 Annotated tags are created with git tag -a .带注释的标签是用git tag -a创建的。 If you do git show <tagname> and you see the commit only, it's a lightweight tag;如果你执行git show <tagname>并且你只看到提交,它是一个轻量级标签; if you see an additional tag message, it's an annotated tag.如果您看到附加标记消息,则它是带注释的标记。

When this happened to us, it was a case of two tags applied for the same commit.当这发生在我们身上时,这是两个标签应用于同一个提交的情况。 You can find if this is the case by running您可以通过运行找到是否是这种情况

# git log --oneline --decorate=short
deba4b4 (tag: v1.1.0.20.0, tag: v1.1.0.19.0) 001 New buildnumber

Here there are two tags, one for version 19 and other for 20. 20 was tagged after 19, but for the same commit.这里有两个标签,一个用于版本 19,另一个用于 20。20 被标记在 19 之后,但用于相同的提交。 In this case describe returned在这种情况下描述返回

# git describe --tags
v1.1.0.19.0

I don't know why it did this, but this is how it seems to work with duplicate tags.我不知道它为什么这样做,但这似乎是如何处理重复标签的。

Another case where this might happen is if you have a tag that is more "near" to you in a branch.另一种可能发生这种情况的情况是,如果您在分支中有一个离您更“近”的标签。 That case has been explained in this blog post .该案例已在此博客文章中进行了解释。

The issue is git tag shows all tags in all branches while git describe only uses tags on commits which are available in the current branch .问题是git tag显示所有分支中的所有标签,而git describe只使用当前分支中可用的提交标签。

Here is an example (the reason why I came here actually):这是一个例子(我实际上来到这里的原因):

 $ git tag | tail -n3
v0.4.0
v0.4.1
v0.4.2

It shows the latest tag available is v0.4.2 , but this is my output of git describe :它显示可用的最新标签是v0.4.2 ,但这是我的git describe输出:

 $ git describe --tags
v0.4.0-2-acd334c

I'm on develop branch.我在开发分支。 When I dig into the log, I see indeed the most recent tags are not available on the current branch:当我深入查看日志时,我确实看到当前分支上没有最新的标签:

 $ git log --oneline --decorate=short | grep 'tag\:' | head -n3
acd334c (tag: v0.4.0) Merge pull request #1061
988fe5e (tag: v0.3.6) Merge pull request #859
5f97274 (tag: v0.3.5) Merge pull request #646

So in my case, the developers decided to create a new release branch exclusively for tagging releases which results that the develop branch is not up to date with the tags anymore.所以就我而言,开发人员决定创建一个专门用于标记发布的新发布分支,这导致开发分支不再与标签保持同步。

Hope that helps and thanks @eis for the idea with checking the logs.希望能帮助并感谢@eis 检查日志的想法。

Most likely from your example, v1.9 is a tag from merge commit.最有可能从您的示例中, v1.9是来自合并提交的标记。

It is expected git behavior by default and you can read more about it here: https://git.kernel.org/pub/scm/git/git.git/commit/?id=80dbae03默认情况下,git 行为是预期的,您可以在此处阅读有关它的更多信息: https : //git.kernel.org/pub/scm/git/git.git/commit/?id=80dbae03

To ignore merge tags when looking for most recent on the current branch you can use --first-parent option.要在当前分支上查找最新版本时忽略合并标签,您可以使用--first-parent选项。

git describe --tags --first-parent --abbrev=0

--first-parent --first-parent

Follow only the first parent commit upon seeing a merge commit.看到合并提交后,只关注第一个父提交。 This is useful when you wish to not match tags on branches merged in the history of the target commit.当您希望不匹配目标提交历史记录中合并的分支上的标签时,这很有用。

Ref: https://git-scm.com/docs/git-describe参考: https : //git-scm.com/docs/git-describe

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

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