Get the commit hash for a tag

后端 未结 5 1252
感动是毒
感动是毒 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:47

    What about git log -1 --format=format:"%H" mylabel

    EDIT:

    Actually a better solution would be :

    git show-ref -s mylabel
    

    EDIT bis: As mentioned in the comments, be careful with annotated commits (which are objects of their own). To have a more generic solution, read @michas answer.

    You can see the difference when you do a git show-ref -d mylabel.


    Resources:

    • git show-ref

提交回复
热议问题