git 用于通过部分 sha-1(至少前 4 个字符)查找提交的算法是什么。 是否有此类算法的任何实现?
最佳答案
在给定部分“01234
”(“short SHA1”)的情况下找到完整 SHA1 的一种非常简单(但无效)的方法是:
git rev-list --all --objects | grep ^01234
实际的做法是:
git rev-parse --verify 01234
在 commit 6269b6b 中有说明
Teach
get_describe_name()
to pass the disambiguation hint down the callchain toget_short_sha1()
.
所以你可以看到sha1_name.c#get_short_sha1()中的算法函数,它将查找:
- objects :
find_short_object_filename(len, hex_pfx, &ds);
- 并在pack files :
find_short_packed_object(len, bin_pfx, &ds);
(参见“Git Internals - Packfiles”)
关于algorithm - git 使用什么算法来查找部分 sha-1(至少前 4 个字符)的提交?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22627193/