问题
I am using tags by applying them to nightly builds. Then later, I want to use the output of describe --tags --match <latest tag>
to tell me how far from the nightly build my images are. This is for QA testing.
I just ran into an error in a clone that is older than the current tag. I ran git fetch --tags, so I see the tag in git tag output, but when I run git describe --tags --match <tagname>
, I get fatal: No tags can describe <head sha1 version number>
. I cannot do a git pull to update the workspace at this point. Why does this happen and is there a workaround? Thanks very much
回答1:
It happens because you only fetch the tag, not the commit history of the tag. git describe
uses this history, which is why it has an error.
The only workaround is to fetch repo's history containing the tag you're interested in, using git fetch <remote-name>
.
回答2:
I just ran into this error with git version 2.8.3
and command git describe --abbrev=0
.
The problem was that while the tag existed in the origin and my local repository was up to date, the tag did not have a commit message.
The error was resolved after I re-tagged the commit with a tag message:
git tag v1.1.1 -m 'some message'
回答3:
Another explanation can be that the repository was cloned with a depth=xyz
setting (which Travis does by default). In that case, the history might be cut off before the most current tag.
Technically, cloning with depth=xyz
creates a shallow clone with entries in .git/shallow
that describe where to cut off history. When git describe
then walks the history it might get to that cut-off point and stops searching for a tag. That even happens if you fetched tags manually after the initial shallow clone with git fetch --tags
.
If this is the problem, you need to unshallow
the repository (or create a full (enough) clone in the first place). See How to convert a Git shallow clone to a full clone? to solve the problem.
回答4:
I actually ran into this error when I have created a git tag based on git reference.
It seems that the git reference was not "in master" and this cause some problems.
So the fix was to find the proper commit reference in master and recreate the tag.
来源:https://stackoverflow.com/questions/6445148/git-fatalno-tags-can-describe-sha1-number