【发布时间】:2016-09-16 18:20:41
【问题描述】:
我正在使用 git diff-index --check --cached HEAD -- 从 git 提交中修剪空白。我想使用快照添加 Jest 测试,但快照文件包含空格,如果我删除它,我的测试总是会失败。所以我想从空白检查中排除 *.js.snap 文件。我如何告诉 git 从git diff-index 中排除*.js.snap(或者**/__snapshots/*)文件?我在 OSX 上使用 bash。
与此同时,我正在通过将提交挂钩更改为交互式来解决该问题:
# 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
【问题讨论】:
标签: git whitespace githooks jestjs