首页 > 解决方案 > 对某些分支使用 git-hooks(使用 Husky 和 ​​git-branch-is)

问题描述

我使用husky​​git-branch-is作为 git 钩子。在我的 package.json 下面

{
"scripts": {
    "test": "jest",
     ...
},
"husky": {
  "hooks": {
    "pre-commit": "git-branch-is master && npm test",
    "pre-push": "git-branch-is master && npm test"
 }
}

使用从分支功能/802提交的此选项,我重新筛选以下错误

Error: Current branch is "feature/802", not "master". 

问题

  1. 如何禁用以“功能”开头的分支的 git 钩子
  2. 仅对masterdevelopment分支应用钩子。
  3. 这可以在不使用 bash 脚本的情况下实现吗?

标签: gitnpmgit-branchpackage.jsonhusky

解决方案


这对我有用。git-branch-is没有必要。

{
  "hooks": {
    "commit-msg": "if [[ $(git rev-parse --abbrev-ref HEAD) = develop ]]; then commitlint -E HUSKY_GIT_PARAMS; fi"
  }
}

推荐阅读