This documentation probably ought to be updated a bit as the word null-ref
is misleading, but you're correct that it is an all-zeros hash ID. Git uses the phrase "null oid" elsewhere, especially internally with a function is_null_oid
. Since "OID" is an acronym it's usually upper-cased in English text, and "null" sometimes comes along for the ride: see, e.g., the 2.18 Release Notes, vs the git cat-file
documentation where it's spelled "null OID".
I personally think git rev-parse
should have an option for spitting this out (along with the hash ID of the empty tree), since SHA-256 OIDs are 64 bytes long instead of 40 bytes long. However, as a stopgap measure, one can use:
null_oid=$(git rev-parse HEAD | sed s/./0/g)
or, taking the hash-object
trick a bit further:
empty_tree=$(git hash-object -t tree --stdin </dev/null)
null_oid=$(echo $empty_tree | sed s/./0/g)
which gets you both and will continue to work in some future Git that has longer OIDs.