8

直到最近——我几天前才注意到这一点——我的 git pre-commit 钩子正在工作。我正在编写一个反应应用程序,并在提交之前使用 Husky、TSLint 和 Prettier 来清理和整理我的代码。现在,当我更改和提交文件时,预提交挂钩不会运行。

我的项目结构如下所示:

- project
  - .git/
  - react/   <- the frontend
    - node_modules/
    - src/
    - package.json
    - (other files)
  - nodejs/  <- the server
    - node_modules/
    - src/
    - package.json
    - (other files)
  - package.json
  - (other files)

如果我手动执行钩子,它似乎运行良好:

[/project/react] # git status
On branch fixHusky
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    modified:   MyFile.ts

[/project/react] # ../.git/hooks/pre-commit
husky > pre-commit (node v12.6.0)
  ↓ Stashing changes... [skipped]
    → No partially staged files found...
  ✔ Running linters...

[/project/react] # 

但是当我真正尝试提交时,哈士奇并没有运行:

[/project/react] #  git commit -m "testing husky"
[fixHusky cf17a6b] testing husky
 1 file changed, 1 insertion(+), 1 deletion(-)

[/project/react] # 

知道为什么它没有运行吗?

4

2 回答 2

11

通过运行更新赫斯基yarn add --dev husky修复了问题。我不知道它为什么停止工作,但无论如何,哈士奇已经过时了。

于 2019-07-19T17:27:33.513 回答
6

检查git config core.hooksPath是否设置为与默认路径不同的路径:$GIT_DIR/hooks

还要检查当前GIT_DIR设置(环境变量)。

在这两种情况下,Git 都会在你期望的地方寻找那个钩子(并且目前有你的预提交钩子)

于 2019-07-18T05:01:02.717 回答