Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git get short hash from regular hash

Tags:

git

github

People also ask

Is git Short commit hash unique?

The only requirement for a git short commit hash is that it's unique within that repository, the git client will use variable length (default: 7) while GitLab seems to always use 8 characters.

What is a git short hash?

The short hash is just a shorter version of the original (long) hash. The original Git hash is 40 bytes long while short is only 8 bytes long. However, it becomes difficult to manage it (in terms of using typing or displaying), and that's why the short version is used.

How do I view commit hash?

If you have the hash for a commit, you can use the git show command to display the changes for that single commit. The output is identical to each individual commit when using git log -p .

What is SHA value in git?

That's the hash value. According to Wiki: In cryptography, SHA-1 (Secure Hash Algorithm 1) is a cryptographic hash function that takes an input and produces a 160-bit (20-byte) hash value known as a message digest – typically rendered as a hexadecimal number, 40 digits long.


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.


$ git rev-parse --short 1a6f39665adf05810f70b37ef6470bbcf61fcd38
1a6f396