跳转到主要内容
kitlocal.dev

Git Hooks 生成器

本地运行

100% 在你的浏览器中处理。输入和输出绝不会离开你的设备。

生成 pre-commit、pre-push 等 Git 钩子脚本。

Hook 管理工具
包管理器
Git Hook 阶段
Pre-Commit 检查项

pre-commit

# Block accidental commit of .env secrets
if git diff --cached --name-only | grep -qE "(^|/)\.env($|\.)" && ! git diff --cached --name-only | grep -qE "\.env\.example$"; then
  echo "Error: Refusing to commit .env secret file. Unstage it first." >&2
  exit 1
fi
npx --no -- lint-staged
npm run typecheck

安装步骤

npx --no -- husky init
# Save script into .husky/pre-commit

配套配置文件

{
  "lint-staged": {
    "*.{ts,tsx,js,jsx}": [
      "eslint --fix",
      "prettier --write"
    ],
    "*.{json,md,css}": [
      "prettier --write"
    ]
  }
}