Git(Hub) 如何处理短 SHA 可能发生的冲突?
Git 和 GitHub 都显示 SHA 的简短版本——仅前 7 个字符,而不是全部 40 个字符——并且 Git 和 GitHub 都支持将这些短 SHA 作为参数。
例如 git show 962a9e8
例如 https://github.com/joyent/node/commit/962a9e8< /a>
鉴于可能性空间现在降低了几个数量级,“仅仅”268万,Git和GitHub这里如何防止冲突?他们如何处理它们?
Both Git and GitHub display short versions of SHAs -- just the first 7 characters instead of all 40 -- and both Git and GitHub support taking these short SHAs as arguments.
E.g. git show 962a9e8
E.g. https://github.com/joyent/node/commit/962a9e8
Given that the possibility space is now orders of magnitude lower, "just" 268 million, how do Git and GitHub protect against collisions here? And how do they handle them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这些简短的形式只是为了简化视觉识别,让您的生活更轻松。 Git 并不会真正截断任何内容,内部所有内容都将使用完整值进行处理。不过,您可以在方便时使用部分 SHA-1:
These short forms are just to simplify visual recognition and to make your life easier. Git doesn't really truncate anything, internally everything will be handled with the complete value. You can use a partial SHA-1 at your convenience, though:
我有一个提交 ID 为
000182eacf99cde27d5916aa415921924b82972c
的存储库。显示修订版本,但
打印
(如果您好奇,它是 git 本身的 git 存储库的克隆;该提交是 Linus Torvalds 在 2005 年所做的提交。)
I have a repository that has a commit with an id of
000182eacf99cde27d5916aa415921924b82972c
.shows the revision, but
prints
(If you're curious, it's a clone of the git repository for git itself; that commit is one that Linus Torvalds made in 2005.)
这里有两个注意事项:
如果您在显示提交的 GitHub 页面上的任意位置键入 y,您将看到所述提交的完整 40 个字节。
这说明了 emboss 的观点:GitHub 不会截断任何内容。
无论如何,自 2010 年以来 7 个十六进制数字(28 位)是不够的。
请参阅 Linus Torwalds 本人的 commit dce9648(2010 年 10 月,git 1.7.4.4):< /p>
(BK = BitKeeper)
Two notes here:
If you type y anywhere on the GitHub page displaying a commit, you will see the full 40 bytes of said commit.
That illustrates emboss's point: GitHub doesn't truncate anything.
And 7 hex digits (28 bits) isn't enough since 2010 anyway.
See commit dce9648 by Linus Torwalds himself (Oct 2010, git 1.7.4.4):
(BK = BitKeeper)