Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"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? The v2.0 tag is already pushed, so I am guessing that I can't just delete and re-add it.

like image 672
knipknap Avatar asked Nov 11 '10 12:11

knipknap


People also ask

What does git describe -- tags do?

The `git describe` command finds the most recent tag that is reachable from a commit. If the tag is on the current commit, then only the tag is shown. Otherwise, it shows the tag name appended with the number of additional commits and the abbreviated SHA of the current commit.

What is git describe dirty?

If the working tree has local modification "-dirty" is appended to it. If a repository is corrupt and Git cannot determine if there is local modification, Git will error out, unless '--broken' is given, which appends the suffix "-broken" instead.

How do you fetch a tag?

To fetch tags from your remote repository, use “git fetch” with the “–all” and the “–tags” options. Let's say for example that you have a tag named “v1. 0” that you want to check out in a branch named “release”. Using this command, you have successfully checked out the “v1.


2 Answers

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 additional tag message, it's an annotated tag.

like image 182
knittl Avatar answered Oct 15 '22 04:10

knittl


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.

like image 42
eis Avatar answered Oct 15 '22 03:10

eis