19

I've been working on GIT for quite sometime now.

However, I could not find difference between 'Commit Id' and 'SHA1 - hash value'

What is the difference between 'Commit ID' and 'SHA1'? Any simple explanation with an example would be nice

Ankur Loriya
  • 3,276
  • 8
  • 31
  • 58
Sathish Kumar
  • 2,150
  • 10
  • 29
  • 51
  • 3
    it's the same thing, only the id can be shorter than the full SHA1 (as long as it uniquely identifies the commit) – Sergio Tulentsev May 03 '17 at 15:11
  • 1
    @SergioTulentsev The commit ID is always exactly the SHA1 of the commit; in most contexts, you can specify an unambiguous prefix of the commit ID as an equivalent reference to the commit. – chepner May 03 '17 at 15:30

2 Answers2

21

Commit ID is what identifies a commit. Sometimes, you will see the shorthand version which is just the first seven characters of the actual commit ID versus the full hash.

Consider the following example:

[master 42e2e5a] Added a new readme file to illustrate commit IDs.
1 file changed, 1 insertion(+)
create mode 100644 myreadme

Notice it is showing the shorthand version of the commit ID. Because the actual commit ID is forty hexadecimal characters that specify a 160-bit SHA-1 hash.


Example

Full commit ID

git show -s --format=%H

Result

42e2e5af9d49de268cd1fda3587788da4ace418a

Shorthand version

git show -s --format=%h

Result

42e2e5a

But notice they are the same.

blacktide
  • 10,654
  • 8
  • 33
  • 53
Eddie Martinez
  • 13,582
  • 13
  • 81
  • 106
  • Or what is known as content addressable. Some other merkle tree implementations, like ZFS, use addresses as references instead of just the content. – Bengie Apr 03 '18 at 15:39
6

I've read the answers provided before and I think there's a little thing to add to them. A revision always points to a sha1 (it doesn't actually point, a revision is identified by its sha1 ID but bear with me) but objects in git's DB can be: revisions, trees, blobs, etc and they are all identified by sha1 IDs. So a revision implies using a sha1 ID (to identify it... but there are other sha1 IDs used in a revision like for parents, tree object) but a sha1 ID doesn't necessarily mean it's a revision.

eftshift0
  • 26,375
  • 3
  • 36
  • 60