Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does git rev-parse --short use a non-default length?

Tags:

git

When running git rev-parse --short HEAD on repository A I get a hash output of length 7 as that is the default length for the --short option in the git documentation.

When running the same command within repository B I get a hash output of length 9. What could override the default length of the --short option probably on a per-repository basis?

like image 853
BlackVegetable Avatar asked May 31 '17 13:05

BlackVegetable


1 Answers

Looks like the documentation is out of date. This could happen due to one of two things:

  1. There is a duplicate hash of length 8 in repository B. git rev-parse --short will try to return a unique hash string. This seems unlikely but theoretically possible.

OR

  1. There are a lot of packed objects in this repo and git rev-parse --short will actually give a number no smaller than 7 but that might be higher due to the number of packed objects in the repo.

https://git-scm.com/docs/git-config#git-config-coreabbrev

Set the length object names are abbreviated to. If unspecified or set to "auto", an appropriate value is computed based on the approximate number of packed objects in your repository, which hopefully is enough for abbreviated object names to stay unique for some time.

So the official docs are out of date and the --short option doesn't force the length to 7, even if I haven't overriden the length (which I hadn't.)

like image 159
BlackVegetable Avatar answered Oct 22 '22 00:10

BlackVegetable