使用 `@commitlint` 改进 Git 提交
在团队协作开发项目时,Git是一个至关重要的工具,它能帮助团队顺畅地协作。其关键特性之一是快照commits功能,该功能类似于项目进度的快照。
但是,你知道我的哪一次提交添加了新功能吗?我敢肯定你不知道,包括我自己也不知道……
问题是我随意命名提交时没有查看上下文,这让我很难确定何时需要撤销更改。
为了解决这个问题,可以使用一个名为 `linter` 的实用代码commitlint检查工具。它可以防止我们随意命名提交。
// git commit
git commit -m "oops"
// it will trigger this error
// ❌ type must be one of [build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test] [type-enum]
并强制我们正确命名提交。
git commit -m "fix: resolve the issue related to comma"
git commit -m "feat: add a feature named calculator"
上下文非常清晰易懂,对吧?
以下是所有建议和提供的类型,commitlint包括示例提交:
- 构建--> 影响构建系统或外部依赖项的更改
git commit -m "build: update npm dependency"
- ci --> 对我们的 CI 配置文件和脚本的更改
git commit -m "ci: add circleci configuration file"
- 文档--> 仅文档更改
git commit -m "docs: update readme with installation instructions"
- 功能--> 一项新功能
git commit -m "feat: add user authentication feature"
- 修复--> 错误修复
git commit -m "fix: resolve issue with incorrect data rendering"
- 性能--> 提高性能的代码更改
git commit -m "perf: optimize database query for faster response times"
- 重构--> 既不修复错误也不添加新功能的代码更改
git commit -m "refactor: reorganize code structure for better readability"
- 样式--> 不影响代码含义的更改(空格、格式、缺失的分号等)
git commit -m "style: format code according to Prettier standards"
- 测试--> 添加缺失的测试或更正现有测试
git commit -m "test: add unit tests for user authentication"
有很多功能commitlint我无法一一列举,安装指南也是如此。要了解详情,您可以直接访问https://github.com/conventional-changelog/commitlint。

