规范的提交信息有助于团队成员理解代码更改的目的和内容,提高代码审查和项目维护的效率。主要好处包括:
提交信息通常由三部分组成:
标题是提交信息的第一行,应简明扼要地描述更改的主要内容。长度应限制在50个字符以内。
主体部分对更改进行详细说明,包含更改的动机、内容和可能的影响。每行长度应限制在72个字符以内。
页脚部分包含提交的元数据,如相关任务编号、受影响的模块、BREAKING CHANGE等。
为了提高提交信息的可读性和一致性,建议使用以下类型前缀:
<type>(<scope>): <subject>
主体部分应详细描述更改的内容和动机,必要时可以包括以下信息:
页脚部分可以包括以下内容:
feat(authentication): add OAuth2 login support
Added support for OAuth2 login using Google and Facebook. This allows users to log in with their social media accounts, improving user experience and security.
BREAKING CHANGE: Updated the user model to include OAuth2 tokens. Existing users need to update their profiles.
fix(login): correct password validation error
Fixed a bug where the password validation function incorrectly rejected valid passwords. Updated the validation regex and added additional unit tests to cover edge cases.
Closes #123
docs(README): update setup instructions
Updated the setup instructions in the README file to include the new environment variables required for OAuth2 login.
See also #456
为了帮助团队成员遵循提交信息书写规范,可以使用以下工具:
Commitizen:帮助生成符合规范的提交信息。
npm install -g commitizen
使用:
git cz
Husky:Git hooks工具,可以在提交前自动检查提交信息。
npm install husky --save-dev
Commitlint:用于验证提交信息是否符合规范。
npm install @commitlint/config-conventional @commitlint/cli --save-dev
配置:
echo "module.exports = {extends: ['@commitlint/config-conventional']};" > commitlint.config.js
通过以上工具,可以在提交前自动检查和生成规范的提交信息,确保团队成员遵循提交信息书写规范。
这份指南详细介绍了提交信息书写规范的各个方面,从基本结构到具体格式和示例,希望对你有所帮助。