1

I understand how blob sha1 is created , I understand what goes in for hash calculation for tag. Can anyone tell me or point me to the appropriate doc which explains commit object hash creation?

Abhijit Mazumder
  • 8,641
  • 7
  • 36
  • 44

2 Answers2

1

The bottom portion of this (Git Objects) page explains how the objects are generated and passed into the hashing function.

Basically, git takes the content of the item you are storing, generates a header with the length of the blob, combines them together (store = header + content), and takes the SHA1 hash of store.

Ryen Nelsen
  • 367
  • 1
  • 9
  • Hi Ryan, it definitely says what a commit object consists of and *can be figured out* how its done, but there is no definitive description on SHA1 generation for commit object – Abhijit Mazumder Mar 06 '15 at 07:17
0

Okay I figured it out.

Following things go in creating commit sha object

  1. tree object reference
  2. parent object reference
  3. author name
  4. author commit timestamp with timezone (e.g for me its +530) [could be different from commiter for example in case of cherry picking]
  5. committer name
  6. commit timestamp with timezone (e.g for me its +530)
  7. commit message

I was trying to figure out why commit SHA ids are different after resetting and again adding the same file with exact same commit message by the same user with same parent and tree object reference .

Now I know its for timestamp. Wanted to share this.

Abhijit Mazumder
  • 8,641
  • 7
  • 36
  • 44
  • You should have asked your actual question "why is the SHA different". It's a duplicate of http://stackoverflow.com/questions/23791999/why-does-git-commit-amend-change-the-hash-even-if-i-dont-make-any-changes and others for instance. – Andrew C Mar 07 '15 at 16:56
  • Thanks for the link ;btw it does not say about parent though – Abhijit Mazumder Mar 07 '15 at 17:17