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

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

问题描述

如果您要构建一个目录结构,其中一个目录以 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./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

但我觉得那会很冒险.但是假设一个代码库在几年内可能会发生(比如说)3 万次更改,如果我使用 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 章:

一般来说,八到十个字符就足够了在一个项目中.最大的 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 are the Git default for a short SHA, so that's fine for most projects. The Kernel team has increased theirs several times, as mentioned because they have several hundred thousand commits. So for your ~30k commits, 8 or 10 digits should be perfectly fine.

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

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