0

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?

1 Answers1

3

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:

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250