Making git output full (un-abbreviated) hashes for all commands?
The new updated answer (2021) will be with Git 2.31 (Q1 2021)
The configuration variable 'core.abbrev
' can be set to 'no
' to force no abbreviation regardless of the hash algorithm.
And that will be important when Git will switch from SHA1 to SHA2.
See commit a9ecaa0 (01 Sep 2020) by Eric Wong (ele828
).
(Merged by Junio C Hamano -- gitster
-- in commit 6dbbae1, 15 Jan 2021)
core.abbrev=no
: disables abbreviationsSigned-off-by: Eric Wong
This allows users to write hash-agnostic scripts and configs by disabling abbreviations.
Using "
-c core.abbrev=40
" will be insufficient with SHA-256, and "-c core.abbrev=64
" won't work with SHA-1 repos today.[jc: tweaked implementation, added doc and a test]
git config
now includes in its man page:
If set to "no", no abbreviation is made and the object names are shown in their full length.
Using git -c core.abbrev=40 <command>
is supposed to work on all commands because it "will override whatever is defined in the config files".
It seems to have been introduced in 8b1fa778676ae94f7a6d4113fa90947b548154dd
(landed in version 1.7.2).
Edit2: As phils noticed, the core.abbrev
parameter was added in 1.7.4.4.
Edit: W.r.t. hardcoded hash lengths, you could always look up the hash lengths by looking at the filename lengths in .git/objects/*
when initializing your program/library.