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

查看:155
本文介绍了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天全站免登陆