将 commitlint 添加到 husky 中的 commit-msg 挂钩的正确方法是什么?
What is the correct way to add commitlint to the commit-msg hook in husky?
我有一个 angular 项目,我想在其中强制执行常规提交。我一直没能成功对上hook,防止不正确的hook。
我从 this tutorial 开始,它说要将以下内容添加到 package.json:
{
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
}
这没有用(它仍然导致错误的提交)所以我做了一些研究并发现 this article 上面说的是 husky 4,而对于 husky 5 我应该 运行 这个命令:
npx husky add .husky/commit-msg 'npx commitlint --edit '
据我所知,commitlint official docs 说要以同样的方式进行。但是,当我 运行 它时,我得到了这个不执行任何操作的奇怪提示:
PS C:\...\MyProj> npx husky add .husky/commit-msg 'npx --no-install commitlint --edit '
Usage
husky install [dir] (default: .husky)
husky uninstall
husky set|add <file> [cmd]
这只是令人困惑,因为我写的实际上是在提示的第三行之后。
有没有人经历过这个并且可以帮助我理解我需要做什么?
来自package.json的相关部分:
"scripts": {
"postinstall": "husky install"
},
"private": true,
"devDependencies": {
"@commitlint/cli": "^12.1.1",
"@commitlint/config-conventional": "^12.1.1",
"husky": "^6.0.0"
}
}
似乎有问题运行 npx husky add .husky/commit-msg 'npx --no-install commitlint --edit '
因为命令部分不止一个字。我发现的解决方法是将其分成两部分。
1 - 调用 npx husky add .husky/commit-msg
这在正确的位置创建了一个包含以下内容的空/默认文件:
#!/bin/sh
. "$(dirname "[=10=]")/_/husky.sh"
undefined
2 - 然后我将 undefined
替换为 npx --no-install commitlint --edit
就可以了
This part of the commitlint docs 帮助我明白这样做是可以的
希望这对遇到同样问题的其他人有所帮助!
我有一个 angular 项目,我想在其中强制执行常规提交。我一直没能成功对上hook,防止不正确的hook。
我从 this tutorial 开始,它说要将以下内容添加到 package.json:
{
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
}
这没有用(它仍然导致错误的提交)所以我做了一些研究并发现 this article 上面说的是 husky 4,而对于 husky 5 我应该 运行 这个命令:
npx husky add .husky/commit-msg 'npx commitlint --edit '
据我所知,commitlint official docs 说要以同样的方式进行。但是,当我 运行 它时,我得到了这个不执行任何操作的奇怪提示:
PS C:\...\MyProj> npx husky add .husky/commit-msg 'npx --no-install commitlint --edit '
Usage
husky install [dir] (default: .husky)
husky uninstall
husky set|add <file> [cmd]
这只是令人困惑,因为我写的实际上是在提示的第三行之后。
有没有人经历过这个并且可以帮助我理解我需要做什么?
来自package.json的相关部分:
"scripts": {
"postinstall": "husky install"
},
"private": true,
"devDependencies": {
"@commitlint/cli": "^12.1.1",
"@commitlint/config-conventional": "^12.1.1",
"husky": "^6.0.0"
}
}
似乎有问题运行 npx husky add .husky/commit-msg 'npx --no-install commitlint --edit '
因为命令部分不止一个字。我发现的解决方法是将其分成两部分。
1 - 调用 npx husky add .husky/commit-msg
这在正确的位置创建了一个包含以下内容的空/默认文件:
#!/bin/sh
. "$(dirname "[=10=]")/_/husky.sh"
undefined
2 - 然后我将 undefined
替换为 npx --no-install commitlint --edit
就可以了
This part of the commitlint docs 帮助我明白这样做是可以的
希望这对遇到同样问题的其他人有所帮助!