关于Git 提交消息格式错误的分析
今天把新项目的代码提交到 git 上时,报错了:
> git -c user.useConfigOnly=true commit --quiet --allow-empty-message --file -
╭────────────────────────────────────────╮
│ 🥊 lefthook v1.11.12 hook: pre-commit │
╰────────────────────────────────────────╯
│ lint-vue (skip) no files for inspection
│ lint-json (skip) no files for inspection
│ lint-style (skip) no files for inspection
│ lint-package (skip) no files for inspection
│ lint-md (skip) no files for inspection
│ lint-js (skip) no files for inspection
┃ code-workspace ❯ ────────────────────────────────────
summary: (done in 0.70 seconds)
✔️ code-workspace
╭────────────────────────────────────────╮
│ 🥊 lefthook v1.11.12 hook: commit-msg │
╰────────────────────────────────────────╯
┃ commitlint ❯ ⧗ input: 更改
✖ 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-commitlintexit status 1 ────────────────────────────────────
summary: (done in 0.44 seconds)
🥊 commitlint
直接懵逼,
这是什么玩意儿?
这个是啥错误??
为啥啊???
后来研究了一下才知道,提交消息也是有格式的,从前一直没把这个提交消息看的很重,就是简单写一下提交的功能文字描述就行了,实在不想写了就直接写:commit
对于现在新项目来讲,这是不行的。
于是整理了一下常用的提交格式:
新功能 → feat修复问题 → fix文档更新 → docs代码优化 → refactor样式调整 → style测试相关 → test配置变更 → chore
使用方法:
git commit -m "feat: 添加功能"
git commit -m "fix: 修复支页面显示错误"
git commit -m "docs: 更新安装指南"
……
就可以了。
