I'm trying to understand why the command "git describe --tags --abbrev=0" doesn't return me the last tag I've created with Git.
That's what I've done.
Step 1: Tag creation
I've executed the following commands:
git tag 1.0.1
git tag 1.0.2
git tag 1.0.3
git tag 1.0.4
git tag 1.0.5
git tag 1.0.6
git tag 1.0.7
git tag 1.0.8
git tag 1.0.9
git tag 1.0.10
git tag 1.0.11
git tag 1.0.12
Step 2 - Getting the list of all tags:
I've executed the following command:
git tag
The result is the following:
1.0.0
1.0.1
1.0.10
1.0.11
1.0.12
1.0.2
1.0.3
1.0.4
1.0.5
1.0.6
1.0.7
1.0.8
1.0.9
Step 3 - Getting the last tag:
I've executed the following command:
git describe --tags --abbrev=0
The result is the following:
1.0.1
Shouldn't it be "1.0.12"?
CodePudding user response:
Note that this git describe --tags --abbrev=0
is an exception:
Git - git-describe Documentation
By default (without --all or --tags)
git describe
only shows annotated tags. For more information about creating annotated tags see the -a and -s options to git-tag[1].
And you have used none annotated tags:
Tag objects (created with
-a
,-s
, or-u
) are called "annotated" tags; they contain a creation date, the tagger name and e-mail, a tagging message, and an optional GnuPG signature. Whereas a "lightweight" tag is simply a name for an object (usually a commit object).Annotated tags are meant for release while lightweight tags are meant for private or temporary object labels. For this reason, some git commands for naming objects (like
git describe
) will ignore lightweight tags by default.
So since you didn't used annotated tags, so there is no creation date for them. This means git doesn't have information which tag is older and selects one randomly (first which he can find) if they are pointing to same commit.
So try use annotated tags, then git will have means to order tags based on they creation date.
CodePudding user response:
git describe
is not the same as git tag
. git describe
is used to describe a commit. git tag
is used to list all tags.
git describe --tags --abbrev=0
will describe the commit with the closest tag.
If you want to get the last tag, you can use
git tag | tail -n 1