gitgit-taggit-describe

Git describe giving different tags


I have tagged my repository with the tag "Release_V1.0.0.4". But here is what I got from "git describe" and "git describe origin".

[root pds_series]# git describe

Release_V1.0.0.2-22-g0859de9

[root pds_series]# git describe origin

Release_V1.0.0.2-18-gce2b24c

With "git describe --all" and "git describe --tags" I got the right tag.

[root pds_series]# git describe --all

tags/Release_v1.0.0.4

[root pds_series]# git describe --tags

Release_v1.0.0.4

Also, with following command I got the right tag.

[root pds_series]# git log --pretty=format:'%ad %h %d' --abbrev-commit --date=short -1

2012-11-15 0859de9 (HEAD, Release_v1.0.0.4, master)

Do anyone know the reason behind this ? How can I resolve this issue ?


Solution

  • You probably used a "lightweight" tag. By default git describe only uses tag objects to describe a commit whereas with --tags it will use any reference under refs/tags even if they point directly to a commit rather than a tag object.

    To create a tag object you must use one of -a (annotated) or -s or -u (signed) options to git tag, otherwise a lightweight tag (a reference pointing straight to a commit) will be created.

    To see the difference between your two tags try:

    git cat-file -t Release_V1.0.0.2
    

    and:

    git cat-file -t Release_v1.0.0.4
    

    On will probably say "tag" and the other will say "commit".

    To resolve the issue you can recreate the tag with -f and (say) -a.

    git tag -f -a Release_v1.0.0.4 Release_v1.0.0.4