Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git SHA1 0000000000000000000000000000000000000000 (all zeroes), is this normal?

Tags:

git

sha

I have a yet uncommited branch in git with SHA1 0000000000000000000000000000000000000000 (all zeroes), is this normal or did I corrupt the git repository?

Please don't answer yes there's one in 2^160, or 0.00000000000000000000000000000000000000000000006842277657836021% probabilities to have that SHA1.

I am reasonably safe I'm not the lucky guy who got the SHA1 of 0000000000000000000000000000000000000000 in his git repository.

like image 326
dendini Avatar asked Sep 24 '13 09:09

dendini


2 Answers

Note, you can find the "all-zeros SHA1" all the way back to commit f65fdf (June 30th, 2005, v0.99 of git)

Linus Torvalds:

A "old ref" of all zeroes is considered a "don't care" ref, and allows us to say "write the new ref regardless of what the old ref contained (or even if it existed at all)".

This allows (if git-send-pack were to do it) creating new refs, and fixing up old ones.


As SzG mentioned in the comments, this is the kind of SHA1 you find in Git receive/update hooks and new branches, representing an "old-ref" for a non-existent object (while the "new-ref" would create said object, like a branch).

like image 117
VonC Avatar answered Oct 05 '22 10:10

VonC


A commit includes, among other metadata, the commit date. So the commit hash can't be displayed until the commit has actually been created. What you're seeing is not a commit SHA, it's just a default value used in the UI.

like image 23
Mat Avatar answered Oct 05 '22 11:10

Mat