Husky配置文件没有执行权限

发现问题

最近在项目中使用husky@7.0.1给 git 添加执行钩子时发现在 window 系统上可以正常触发配置的 pre-commit 但是在 mac 上就是不行并且在控制台输出一下提示:

hint: The '.husky/pre-commit' hook was ignored because it's not set as executable.
hint: You can disable this warning with `git config advice.ignoredHook false`.
hint: The '.husky/commit-msg' hook was ignored because it's not set as executable.
hint: You can disable this warning with `git config advice.ignoredHook false`.

然后进入到项目中的.husky 文件夹中查看权限,果然没有执行权限
1

分析原因

为啥就 commit-msg 和 pre-commit 这俩文件没有执行权限?突然想起这些文件都是命令行创建的,唯独这俩文件因为修改过把源文件删了又手动创建了,导致权限不够

解决办法

没有权限就增加权限

chmod +x .husky/*

所以,要解决这类问题,我们要避免手动添加 hook 文件,使用 yarn husky add .husky/这个命令来添加。

参考文档:
Husky needs to make executable for every new branch