und*_*ned 8 git whitespace githooks jestjs
我正在使用git提交修剪空白git diff-index --check --cached HEAD --.我想使用快照添加Jest测试,但快照文件包含空格,如果删除它,我的测试将始终失败.所以我想*.js.snap从空白检查中排除文件.如何告诉git从中排除*.js.snap(或替代**/__snapshots/*)文件git diff-index?我在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
Run Code Online (Sandbox Code Playgroud)
正如这里提到的, 的路径参数git diff-index是 glob 样式模式,由 shell 解释。
所以这更像是一个 shell 问题而不是 git 命令问题。
例如,请参阅“在 unix/linux shell 中进行模式匹配时如何使用反向或负通配符? ”
您可以尝试激活shopt extglob,或者(更简单)对脚本执行后一步,查找(使用git status)完整路径名中的任何已修改文件**/__snapshots/*,并取消它们的修改(git checkout)。
| 归档时间: |
|
| 查看次数: |
1081 次 |
| 最近记录: |