Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between 'Commit ID' and 'SHA1 Hash' in GIT? [duplicate]

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

like image 244
Sathish Kumar Avatar asked May 03 '17 15:05

Sathish Kumar


People also ask

Is commit ID and SHA the same?

Commit IDs are unique SHA-1 hashes that are created whenever a new commit is recorded. If you specify a commit ID when you add a repository, Domino will always pull the state of the repository specified by that commit in a detached HEAD state.

What is SHA1 hash in git?

The algorithm that Git uses is the SHA-1 hash algorithm which basically is a cryptographic hash function taking input and producing a 160-bit (20-byte) hash value.

What is a git commit ID?

Learn how to find the hash of a git commit To find a git commit id (or hash), you can simply use the git log command. This would show you the commit history, listing the commits in chronological order, with the latest commit first.

What does git commit do what's a SHA in the context of Git?

commit is. A commit, or "revision", is an individual change to a file (or set of files). It's like when you save a file, except with Git, every time you save it creates a unique ID (a.k.a. the "SHA" or "hash") that allows you to keep record of what changes were made when and by who.


2 Answers

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.

like image 110
Eduardo Dennis Avatar answered Oct 02 '22 15:10

Eduardo Dennis


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.

like image 23
eftshift0 Avatar answered Oct 02 '22 17:10

eftshift0