Take the 2-minute tour ×

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?

share|improve this question
Have you checked the source code? –  Tim Castelijns Mar 25 at 6:46
This question is off-topic because Stack Overflow is for questions about writing code. –  Adi Inbar Mar 25 at 7:08
To me this question makes sense and looks a valid Stack Overflow question. –  Learner Mar 25 at 8:23

1 Answer 1

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 to get_short_sha1().

So you can see the algorithm in sha1_name.c#get_short_sha1() function, which will looks in:

share|improve this answer

Your Answer


