简单易用的本地Git Hooks新方式
使用
自动(推荐)
git 创建一个空的目录
npm init
npx husky-init && npm install
husky-init
npx husky-init && yarn
a one-time command to quickly initialize a project with husky.
It will setup husky, modify package.json and create a sample pre-commit hook that you can edit. By default, it will run npm test when you commit.
husky add
手动
yarn add husky --dev
yarn husky install
// package.json
{
"private": true, // ← your package is private, you only need postinstall
"scripts": {
"postinstall": "husky install"
}
}
{
"private": false, // ← your package is public
"scripts": {
"postinstall": "husky install",
"prepack": "pinst --disable",
"postpack": "pinst --enable"
}
}
uninstall
yarn remove husky && git config --unset core.hooksPath