Guillaume Bois
Guillaume Bois

Reputation: 1331

git describe not showing most recent tag as advertised

I am on git version 2.40.1

I'm simply looking the get the most recent tag number from a given branch. Not the overall latest tag number from the whole repo. Not a random old tag number.

For example,

I want to be able to checkout master branch, get the most recent tag would return me 1.1.2.

If I switch to be on test branch, getting the most recent tag would return me 1.2.9

Reading from git documentation, git describe says: "The command finds the most recent tag that is reachable from a commit."

My local repo is on branch test. I just created a new tag after merging from a dev branch (tag 6.16.15). But when I do git describe is gives me a very old tag number (6.6.10-1137-gb5a1f2d). I know I can use the --abbrev=0 to chop off the useless suffix, but even then, the tag number is not the most recent one.

git describe --tags give me the right tag number.

git describe does not give me the most recent tag.

Why is the git documentation lying?

Though the git describe --tags seems to work in my case, I feel uneasy to use an additional parameter when the documentation says that I should get what I am looking for without the --tags parameter. Am I just being lucky?... I need to be sure of what is going on here because I am going to program this in install scripts and I need to be sure I am installing the most recent tag number from a given branch.

Upvotes: 1

Views: 576

Answers (1)

knittl
knittl

Reputation: 265564

git describe without any option arguments will only show annotated tags:

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.

If you want to use any tags (including lightweight tags) in the describe output, specify --tags:

Instead of using only the annotated tags, use any tag found in refs/tags namespace. This option enables matching a lightweight (non-annotated) tag.

Upvotes: 2

Related Questions