“git describe” ignores a tag

蓝咒 提交于 2019-11-29 22:47:54

git describe uses only annotated tags by default. specify the --tags option to make it use lightweight tags as well

make sure you've checked out the correct commit (git rev-parse HEAD). annotated tags are created with git tag -a. if you do git show <tagname> and you see the commit only, it's a lightweight tag, if you see an additionial 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. 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.

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:

 $ 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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!