The --abbrev-commit
flag can be used in conjunction with git log
and git rev-list
in order to show partial prefixes instead of the full 40-character SHA-1 hashes of commit objects. According to the Pro Git book,
it defaults to using seven characters but makes them longer if necessary to keep the SHA-1 unambiguous [...]
Additionally, short SHAs are at least 4-character long. Still according to the Pro Git book,
Generally, eight to ten characters are more than enough to be unique within a project.
As an example, the Linux kernel, which is a pretty large project with over 450k commits and 3.6 million objects, has no two objects whose SHA-1s overlap more than the first 11 characters.
Since the length of the longest prefix required to prevent any overlap among all prefix hashes of commit objects (11, in the case of the Linux kernel) is a crude indicator of a repo's size, I'd like to programmatically determine the corresponding quantity in my own local repository. How can I do that?