git - Husky v5 不创建 Git 钩子
问题描述
我已经在我的应用程序中安装了 Husky v5,我想在提交时运行该lint-staged
命令。
我遵循了入门文档,但在我的 git 配置文件中没有创建 .git/hooks/pre-commit 文件。
所以,当我提交时,钩子没有运行,提交直接通过,没有被 lint-staged 检查。
我试过跑步yarn add -D husky@next
或npm i -D husky@next
。我还尝试删除 node_modules 和 npm 重建。
.husky/预提交
#!/bin/sh
[ -z "$CI" ] && exit 0
. "$(dirname $0)/_/husky.sh"
lint-staged
包.json
"scripts": {
"postinstall": "husky install"
},
解决方案
husky v5 不生成钩子(不能说为什么)
所以我降级到 4.3.8 并删除了 .git/hooks(不是必需的):
rm -rf .git/hooks
yarn add -D husky@4.3.8