我正在尝试设置一个预提交挂钩以在任何提交通过之前测试我的项目,但我找不到如何确保只测试 HEAD(带有当前提交的补丁)而不是当前的 working_tree (在大多数情况下,这对我来说很脏)。
找到的解决方案:
找到此链接并最终执行以下操作。
http://newartisans.com/2009/02/building-a-better-pre-commit-hook-for-git/
# Checkout a copy of the current index into MIRROR
git checkout-index --prefix=$TMPDIR/ -af
# Remove files from MIRROR which are no longer present in the index
git diff-index --cached --name-only --diff-filter=D -z HEAD | \
(cd $TMPDIR && xargs -0 rm -f --)