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,
- the
devbranch can be on a commit that is tagged 1.3.4 - the
testbranch can be on a commit that is tagged 1.2.9 - the
masterbranch can be on a commit that is tagged 1.1.2
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.
git describewithout any option arguments will only show annotated tags:If you want to use any tags (including lightweight tags) in the describe output, specify
--tags: