Abhijit Mazumder
Abhijit Mazumder

Reputation: 9434

How is a Git Commit Object SHA1 Created?

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?

Upvotes: 1

Views: 216

Answers (2)

Abhijit Mazumder
Abhijit Mazumder

Reputation: 9434

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.

Upvotes: 0

Ryen Nelsen
Ryen Nelsen

Reputation: 387

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.

Upvotes: 1

Related Questions