Appearance
故障排除
¥Troubleshoot
未找到命令
¥Command not found
查看 如何 了解解决方案。
¥See How To for solutions.
钩子未运行
¥Hooks not running
验证文件名是否正确。例如,
precommit或pre-commit.sh是无效名称。请参阅 Git hooks documentation 以获取有效名称。¥Verify the file name is correct. For example,
precommitorpre-commit.share invalid names. Refer to the Git hooks documentation for valid names.运行
git config core.hooksPath并确保它指向.husky/_(或你的自定义 hooks 目录)。¥Run
git config core.hooksPathand ensure it points to.husky/_(or your custom hooks directory).确认你的 Git 版本高于
2.9。¥Confirm your Git version is above
2.9.
.git/hooks/ 卸载后不起作用
¥.git/hooks/ Not Working After Uninstall
如果卸载 husky 后 .git/hooks/ 中的钩子不起作用,请执行 git config --unset core.hooksPath。
¥If hooks in .git/hooks/ don't work post-uninstalling husky, execute git config --unset core.hooksPath.
Windows 上的 Yarn
¥Yarn on Windows
在 Windows 上使用 Git Bash (stdin is not a tty) 时,Git 钩子可能会与 Yarn 一起失败。对于 Windows 用户,请实现此解决方法:
¥Git hooks might fail with Yarn on Windows using Git Bash (stdin is not a tty). For Windows users, implement this workaround:
创建
.husky/common.sh:¥Create
.husky/common.sh:
shell
command_exists () {
command -v "$1" >/dev/null 2>&1
}
# Workaround for Windows 10, Git Bash, and Yarn
if command_exists winpty && test -t 1; then
exec < /dev/tty
fi在运行 Yarn 命令的地方获取它:
¥Source it where Yarn commands are run:
shell
# .husky/pre-commit
. .husky/common.sh
yarn ...