11

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.

dendini
  • 3,842
  • 9
  • 37
  • 74
  • What is an uncommitted branch? Which git operation produces this value? – SzG Sep 24 '13 at 09:20
  • Possibly related http://stackoverflow.com/questions/1902340/can-a-sha-1-hash-be-all-zeroes – Fredrik Pihl Sep 24 '13 at 09:21
  • 16
    have you considered mining for bitcoins? – necromancer Sep 24 '13 at 09:21
  • 1
    It would be cool though, if you were. – troelskn Sep 24 '13 at 09:21
  • probably this is simply indication that there is not a single commit there yet – mvp Sep 24 '13 at 09:21
  • 5
    Git uses all-zeros as the "null SHA1" meaning "nothing yet". Most things won't show you the all-zeros value, what did you do that does? (Hooks see it, for "no previous rev for this ref"; also for "ref deleted".) – torek Sep 24 '13 at 09:23
  • @torek Now I remember. I've seen this hash before, while programming a post-receive hook :-) – SzG Sep 24 '13 at 09:25
  • @ Fredrik Pihl you posted the exact thread I didn't want to come up with @ no_answer_not_upvoted ahah good point @ SzG I open gitk to see the current history and for the currently changed but uncommited branch it shows SHA1 000000.. git log doesn't show current branch SHA1 though – dendini Sep 24 '13 at 09:45

2 Answers2

13

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).

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
11

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.

Mat
  • 202,337
  • 40
  • 393
  • 406