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

自古美人都是妖i 提交于 2019-12-18 13:33:08

问题


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.


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/18977462/git-sha1-0000000000000000000000000000000000000000-all-zeroes-is-this-normal

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!