Get the commit hash for a tag

后端 未结 5 1251
感动是毒
感动是毒 2021-01-01 18:05

It is related to Making git show to show information in a machine parseable format but I am getting tired of the fact that I now have to do a lot of parsing to get the commi

5条回答
  •  盖世英雄少女心
    2021-01-01 18:32

    git help rev-parse says:

       ^{}, e.g. v0.99.8^{}
           A suffix ^ followed by an empty brace pair means the object could be a tag, and dereference the tag recursively until a non-tag object is found.
    

    Generally you use tag^{} to refer to that commit.

    You have two different kind of tags:

    • lightweight tags are just pointers to an existing commit
    • annotated tags are objects on there own which contain a pointer to a separate commit object

    Use git rev-parse tag to get the SHA1 of the tag itself.

    Use git rev-parse tag^{} to get the SHA1 of the underlaying commit.

    For lightweight tags both are the same. For annotated tags they are not.

    You can also use git show-ref -d tag, which will show you both the SHA1 of the tag and the SHA1 of the associated commit.

    There is also git show tag to give you details about an (annotated) tag.

提交回复
热议问题