最近我注意到了一个问题,我的git pre-commit hook不起作用了。我正在编写一个React应用程序,使用Husky、TSLint和Prettier在提交之前清理和lint我的代码。现在,当我修改并提交文件时,pre-commit hook不会运行。
我的项目结构如下:
- 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] #
但是当我真正尝试提交时,husky并没有运行:
[/project/react] # git commit -m "testing husky"
[fixHusky cf17a6b] testing husky
1 file changed, 1 insertion(+), 1 deletion(-)
[/project/react] #
不知道为什么它没运行?
../.git/hooks/pre-commit
而不是./.git/hooks/pre-commit
?也许你有两个.git
目录(../.git
和./.git
)? - aropan../
而不是./
,因为我们的项目有两个目录,一个用于服务器,另一个用于React。Git仓库位于根目录,但是linting应该只在React文件夹中进行。我会编辑问题以使其更清晰明了。 - whiterook6