*一般*认为需要唯一标识给定代码库中的更改的数量是多少? [英] How much of a git sha is *generally* considered necessary to uniquely identify a change in a given codebase?

查看:111
本文介绍了*一般*认为需要唯一标识给定代码库中的更改的数量是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您要构建一个目录结构,其中一个目录在Git存储库中用于提交命名,并且您希望它足够短以使您的眼睛不会流血,但是足够长以至于有机会它的冲突是微不足道的,通常需要多少SHA子字符串?

If you're going to build, say, a directory structure where a directory is named for a commit in a Git repository, and you want it to be short enough to make your eyes not bleed, but long enough that the chance of it colliding would be negligible, how much of the SHA substring is generally required?

假设我想唯一标识这个变化:https://github.com/wycats/handlebars.js/commit/e62999f9ece7d9218b9768a908f8df9c11d7e920

Let's say I want to uniquely identify this change: https://github.com/wycats/handlebars.js/commit/e62999f9ece7d9218b9768a908f8df9c11d7e920

我可以使用前四个字符:
https://github.com/wycats /handlebars.js/commit/e629

I can use as little as the first four characters: https://github.com/wycats/handlebars.js/commit/e629

但我觉得这样做会有风险。但是,假设一个代码库在几年后可能会有30k的变化,如果我使用8个字符,碰撞的可能性有多大? 12?是否有这样的数字通常被认为是可以接受的?

But I feel like that would be risky. But ssuming a codebase that, over a couple of years, might have—say—30k changes, what are the chances of collision if I use 8 characters? 12? Is there a number that's generally considered acceptable for this sort of thing?

推荐答案

这个问题实际上是在 Pro Git书籍第7章

This question is actually answered in Chapter 7 of the Pro Git book:


一般而言,在项目中,八至十个字符足以成为唯一的
。最大的Git项目之一,Linux内核
开始需要可能的40个字符中的12个字符才能保持
的独特性。

Generally, eight to ten characters are more than enough to be unique within a project. One of the largest Git projects, the Linux kernel, is beginning to need 12 characters out of the possible 40 to stay unique.

7位数字是短SHA的Git默认值,所以对于大多数项目来说都没问题。如上所述,内核团队多次增加了他们的数量,因为已经提交了几十万次提交。因此,对于您的30k提交,8位或10位数应该完全正常。

7 digits is the Git default for a short SHA, so that's fine for most projects. The Kernel team have increased theirs several times, as mentioned, because the have several hundred thousand commits. So for your ~30k commits, 8 or 10 digits should be perfectly fine.

这篇关于*一般*认为需要唯一标识给定代码库中的更改的数量是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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