git fatal:No tags can describe <sha1 number>

24,260

Solution 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>.

Solution 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'

Solution 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.

Share:
24,260
user561638
Author by

user561638

Release Engineer with over 25 years experience. Recently started supporting/using git, Jira, Jenkins and embedded linux development. Previoulsy, all my experience was with clearcase/clearquest, and clearmake. I worked at Rational as a senior tech support engineer for a couple of years. Now I am at a startup in stealth mode.

Updated on August 03, 2022

Comments

  • user561638
    user561638 almost 2 years

    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