In git, what is the difference between long and short hashes?

Here is the long git hash:

commit c26cf8af130955c5c67cfea96f9532680b963628

Combine: 8654907 37c2a4f

Posted by: nicolas

Date: Wed Apr 26 13:28:22 2017 -0400

Here is a short

enter image description here

+6
source share
4 answers

A short hash is only the first 7 characters of your full hash.

Right under the rounded lock in the screenshot you can see the fixation with the inscription c26cf8a. This should be the commit c26cf8af130955c5c67cfea96f9532680b963628you were looking for.

+4
source

To talk more about why a short hash is useful and why you often don't need a long hash, it is related to how Git stores things.

c26cf8af130955c5c67cfea96f9532680b963628 . .git/objects/c2/6cf8af130955c5c67cfea96f9532680b963628. , c2 , - . , , .

c26cf8a, Git .git/objects/c2/6cf8a* , , . , , , .

c26cf8a , 16 ^ 7 2 ^ 28 268,435,456, , .

, Git / , .


. Git packfiles. . Git , .git/objects, .git/objects/pack/pack-<checksum>.

, , .:)

+4

7 . c26cf8af130955c5c67cfea96f9532680b963628 - c26cf8a . . document:

Git , , , , SHA-1

+1
source

A short hash is just a shorter version of the original (long) hash. the original git hash is 40 byteslong and the short is long 8 bytes. However, it becomes difficult to control it (in terms of input or display), why the short version is used.

This approach is used in almost all projects where the hash is designed for either integrity(package distribution), versioning(git / svn), or layeredarchitecture (docker).

0
source

Source: https://habr.com/ru/post/1016838/


All Articles