commitlint官方链接
1. npm install --save-dev @commitlint/config-conventional @commitlint/cli
2. 配置commitlint.config.cjs(项目根目录中)
module.exports = {extends: ['@commitlint/config-conventional'],rules: {'type-enum': [2,'always',['Feat', 'Fix', 'Doc', 'Style', 'Update', 'Refactor', 'Test', 'Framework', 'Revert'],],'type-case': [0, 'always', 'start-case'],'type-empty': [0],'scope-empty': [0],'scope-case': [0],'subject-full-stop': [0, 'never'],'subject-case': [0, 'never'],'header-max-length': [0, 'always', 72],},
};
3.在package.json文件中配置scripts
4.通过终端执行npm run prepare生成.husky文件夹
5. 添加hook命令 在根目录中.husky中生成文件命令commit-msg
npx husky add .husky/commit-msg "npx --no-install commitlint --edit '$1'"
6.在.gitignore文件中导入husky
/.husky/_
/.husky/.gitignore
7. 执行操作
git add . git status //查看暂存修改的文件
git commit -m 'fix: 配置'//冒号后面必须加空格再进行文字描述
不正确的提交报错