在它的預提交鉤子git似乎驗證HEAD存在。如果不是,它默認使用空樹的特殊散列來比較索引。爲什麼git的pre-commit hook會驗證HEAD是否存在?
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
它默認的散列是一個特殊的散列。我讀,我也可以通過
git hash-object -t tree < /dev/null
against
得到它以後像這樣使用
# If there are whitespace errors, print the offending file names and fail.
exec git diff-index --check --cached $against --
爲什麼掛鉤做到這一點?在什麼情況下我可以做一個提交但HEAD將是無效的?