Reputation: 9
What is the algorithm git uses to find a commit by a partial sha-1 (at least first 4 characters). Are there any implementations of such algorithm out there?
Upvotes: 0
Views: 225
Reputation: 1323223
One very simple way (but ineffective) to find the full SHA1 given a partial "01234
" one (a "short SHA1")is:
git rev-list --all --objects | grep ^01234
The actual way is:
git rev-parse --verify 01234
It is illustrated in commit 6269b6b
Teach
get_describe_name()
to pass the disambiguation hint down the callchain toget_short_sha1()
.
So you can see the algorithm in sha1_name.c#get_short_sha1() function, which will looks in:
find_short_object_filename(len, hex_pfx, &ds);
find_short_packed_object(len, bin_pfx, &ds);
Upvotes: 3