我正在使用git diff-index --check --cached HEAD --
修改git提交中的空白。我想使用快照添加Jest測試,但快照文件包含空格,如果我刪除它,我的測試總是失敗。所以我想從空白檢查中排除*.js.snap
文件。如何讓git從git diff-index
中排除*.js.snap
(或**/__snapshots/*
)文件?我在OSX上使用bash。從git空白檢查中排除Jest快照
在此期間,我在解決該問題,通過改變我的commit鉤子是互動:
# If there are whitespace errors, print the offending file names and fail.
git diff-index --check --cached HEAD --
if [ $? -ne 0 ]; then
# Allows us to read user input below, assigns stdin to keyboard
exec < /dev/tty
while true; do
echo "Your commit introduces trailing whitespace. Are you sure you want to commit? y/n"
read yn
case $yn in
y) exit 0;;
n) exit 1;;
esac
done
fi
感謝您花時間回答。我花了很多時間玩負面通配符和GLOBIGNORE,但都沒有效果。兩者似乎只適用於不包含多個通配符('**/*')的模式。 – undefined
我還是會獎勵你的賞金,因爲我不能把它給自己,而不是你現在關心的聲譽! – undefined
@undefined感謝您的反饋,併爲您的答案+1。在此之前我提到了pathspec:http://stackoverflow.com/a/38931091/6309和http://stackoverflow.com/a/35622183/6309,以及http://stackoverflow.com/a/33462321/6309中的示例 – VonC