一、問題
git commit 報(bào)錯(cuò):No staged files match any configured task.
> git -c user.useConfigOnly=true commit --quiet --allow-empty-message --file -
[34m→[39m No staged files match any configured task.
? input: feat: XXX
? subject may not be empty [subject-empty]
? type may not be empty [type-empty]
? found 2 problems, 0 warnings
? Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint
husky - commit-msg hook exited with code 1 (error)
二、解決
這就涉及到 git hooks
了,熟悉的小伙伴自不用多說,不熟悉的可以看一下官方文檔:Git - Git 鉤子
如果報(bào)錯(cuò)中有 husky
、commitlint
這樣的關(guān)鍵字眼,那就是前端項(xiàng)目中使用了這兩種 npm
插件,husky
的配置文件在如下截圖位置:
- 最粗暴的解決方式是使用
#
注釋掉最后一行(不建議,急用臨時(shí)提交可行)
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
npx --no -- commitlint --edit ${1}
若是使用 JetBrains公司的系列產(chǎn)品時(shí)(
WebStrom
/PhpStrom
/IDEA
…),可以:去掉勾選(不限前端項(xiàng)目)
- 檢查
package.json
和node_modules
該依賴是否安裝:
{
"devDependencies": {
"@commitlint/cli": "^17.4.4",
"@commitlint/config-conventional": "^17.4.4",
"husky": "^8.0.3",
},
}
我這里最終發(fā)現(xiàn)問題就出現(xiàn)在這里(
package.json
在某次代碼合并中被不知名小可愛覆蓋。。。剛好缺了commitlint
)
- 檢查提交信息是否符合規(guī)范:【筆記】項(xiàng)目?jī)?yōu)化代碼提交規(guī)范 —— commitlint+husky
若是內(nèi)網(wǎng)開發(fā),規(guī)范可見源碼:文章來源:http://www.zghlxwxcb.cn/news/detail-698289.html
node_modules\@commitlint\config-conventional\index.js
- 檢查所有配置之后,確定沒問題的話,那么刪除
node_modules
,然后重新npm i
試試
over文章來源地址http://www.zghlxwxcb.cn/news/detail-698289.html
三、拓展學(xué)習(xí)
到了這里,關(guān)于【已解決】使用 husky、commitlint 后 git commit 報(bào)錯(cuò):No staged files match any configured task.的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!