0

In general commit ID characters length is 40, but you know the previous 7 characters can represent the commit too. Now that the previous 7 code can represent the commit, why the commit code length still be 40?

enter image description here

You can see from the upper snapshot, the parent commit represent code length is 7.


EDIT

I am asking why GitHub chooses to use 40 characters to represent the commit ID but only 7 characters to represent the parent ID?

qg_java_17137
  • 3,310
  • 10
  • 41
  • 84
  • 2
    No the 7-char hex is a shorter version, it is used as a short reference, but in case of ambigity the longer hash should be used, it aims to be a userfriendly name. – Willem Van Onsem Dec 01 '17 at 16:07
  • 1
    it depends on the so far generated guids. if you commit another 3million, you might need 9 to uniquely identify every commit - then do another 30 millions ans you need 15. you need to give git as many as needed to uniquely identify a commit for most actions - not the complete one – Patrick Artner Dec 01 '17 at 16:08
  • If I understand your question correctly, it sounds like you're asking why GitHub chooses to use 40 characters to represent the commit ID but only 7 characters to represent the parent ID? – Edward Thomson Dec 01 '17 at 16:10
  • @EdwardThomson Yes, I mean this. – qg_java_17137 Dec 01 '17 at 16:10
  • 1
    Probably to save space from a design perspective. Having the full 40 would probably mean adding an extra line taking up more vertical space and potentially pushing something else useful off the screen. The only way to really know the answer is to ask GitHub though. @PatrickArtner it's not a guid, it's actually a sha1 hash over the object contents. But the rest of your logic still applies. – John Szakmeister Dec 01 '17 at 16:18
  • @jszakmeister one never stops to learn :) thanks for pointing out my mistake – Patrick Artner Dec 01 '17 at 16:24
  • @jszakmeister and PatrtrickArtner: the implementation is SHA1 for multiple reasons, but it *works as* a GUID, and because of things like [shattered.it](https://shattered.it/) there is a long term plan to move to a different hash. – torek Dec 01 '17 at 17:40
  • @torek I know, but it’s not actually one—which is what I was correcting. :-) – John Szakmeister Dec 01 '17 at 19:22

1 Answers1

1

As mentioned, this is purely a design decision:

  • use 40-hexdigits for the full SHA1 of the current commit.
  • use 7-hexdigits to start representing the parent (or parents, where there are more than one as in this one).
    Note that it does not disambiguate the parent commit since the Linux kernel project needs 11 to 12 hexdigits, while the Git repo itself needs 10 hexdigits to uniquely identify the objects they have.

See more at "How much of a git sha is generally considered necessary to uniquely identify a change in a given codebase?"

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250