【发布时间】:2016-06-13 09:29:55
【问题描述】:
在它的预提交钩子中,git 似乎验证了 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 无效?
【问题讨论】:
标签: git githooks pre-commit-hook