Git(Hub) 如何处理来自短 SHA 的可能冲突? [英] How does Git(Hub) handle possible collisions from short SHAs?

查看:19
本文介绍了Git(Hub) 如何处理来自短 SHA 的可能冲突?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Git 和 GitHub 都显示 SHA 的短版本 - 仅显示前 7 个字符而不是全部 40 个字符 - Git 和 GitHub 都支持将这些短 SHA 作为参数.

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.

例如git show 962a9e8

例如https://github.com/joyent/node/commit/962a9e8

鉴于可能性空间现在低了几个数量级,只是"2.68 亿,如何Git 和 GitHub 在这里可以防止冲突吗?他们又是如何处理的?

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?

推荐答案

这些简短的表格只是为了简化视觉识别并让您的生活更简单.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:

Git 足够聪明,如果您提供前几个字符,只要您的部分 SHA-1 至少有四个字符长且明确——也就是说,当前只有一个对象存储库以该部分 SHA-1 开头.

Git is smart enough to figure out what commit you meant to type if you provide the first few characters, as long as your partial SHA-1 is at least four characters long and unambiguous — that is, only one object in the current repository begins with that partial SHA-1.

这篇关于Git(Hub) 如何处理来自短 SHA 的可能冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆