Git 提交標簽
提交消息格式:
<type>: <description>
(示例:git commit -m "feat: add user login API"
)
標簽 | 適用場景 |
---|---|
feat | 新增功能(Feature)。 |
fix | 修復 Bug(Bug fix)。 |
perf | 性能優化(Performance improvement)。 |
docs | 文檔更新(Documentation changes)。 |
style | 代碼格式調整(空格、分號等,不影響邏輯)。 |
refactor | 代碼重構(既不修復 Bug 也不新增功能)。 |
revert | 回滾之前的提交。 |
chore | 構建/工具變更(如依賴更新、配置文件修改)。 |
test | 測試相關(新增測試用例或重構測試代碼)。 |
build | 構建系統或外部依賴變更(如 Webpack、npm)。 |
ci | CI 配置或腳本變更(如 GitHub Actions、Travis)。 |
BREAKING CHANGE | 重大變更(不兼容的 API 修改,需在描述中注明變更細節)。 |
補充說明
-
原則
? 原子性提交:一個提交只做一件事(如僅實現一個功能或修復一個 Bug)。
? 標簽一致性:團隊需統一標簽命名(如用fix
而非bugfix
)。 -
多行消息示例
git commit -m "feat: add payment module > > - Implement PayPal integration > - Add transaction logging"
-
特殊標記
?BREAKING CHANGE
需在提交正文中詳細說明影響范圍,例如:BREAKING CHANGE: Remove deprecated `getUser()` API. Use `fetchUser()` instead.
為什么需要標簽?
? 自動化工具支持:生成 CHANGELOG、觸發版本號升級(如 feat
→ 小版本,BREAKING CHANGE
→ 大版本)。
? 代碼可追溯性:通過標簽快速定位歷史變更目的。