git get short hash from regular hash

前端 未结 2 1630
名媛妹妹
名媛妹妹 2020-12-14 14:32

I have a regular long SHA-1 hash string. I would like to get the shortest unambiguous SHA-1 hash string version of it. That is, the one I would get by using git log -1

相关标签:
2条回答
  • 2020-12-14 15:08
    $ git rev-parse --short 1a6f39665adf05810f70b37ef6470bbcf61fcd38
    1a6f396
    
    0 讨论(0)
  • 2020-12-14 15:11

    The shortest SHA1 you can get has a length of 4. Rev parse will give you a SHA1 of 7 digits by default with the short option :

    git rev-parse --short 921103db8259eb9de72f42db8b939895f5651489
    921103d
    

    You have to specify 4 to the short option to have the shortest unambiguous SHA1 :

    git rev-parse --short=4 921103db8259eb9de72f42db8b939895f5651489
    92110
    

    You can also set it in the core.abbrev configuration variable.

    0 讨论(0)
提交回复
热议问题