1.4 KiB
1.4 KiB
title, type, tags, last_updated
| title | type | tags | last_updated | |||
|---|---|---|---|---|---|---|
| Atomic Commit | concept |
|
2026-04-25 |
Definition
Atomic Commit(原子提交)是一种 Git 提交粒度原则——每次提交仅包含一个逻辑变更单元(一个清晰的改动),易于审查、回滚和溯源,不捆绑多个不相关的变更。
Characteristics
- 单一职责:一个 commit = 一个清晰的改动
- 可独立回滚:回滚一个 commit 不会影响其他功能的正常运行
- 可独立审查:reviewer 能在短时间内理解单个 commit 的意图
- 易于溯源:通过 commit message 快速定位引入特定行为的 ticket
Anti-patterns
| 反模式 | 描述 | 风险 |
|---|---|---|
| Mega commit | 一次性提交大量不相关变更 | review 成本高;回滚连带损伤 |
| WIP commit | 包含 work-in-progress 代码的提交 | 污染历史,难以理解 |
| Fixup commit | 在 review 过程中不断追加修改 | 历史难以重建 |
| Bundled commit | 将多个功能捆在一个 commit 里 | 拆分困难,回滚粒度过粗 |
Relationship to Branch Strategy
Atomic Commit 与 Branch-Strategy 共同构成 Jira-Git-Traceability 的基础:
- Branch 隔离不同任务的工作
- 每个 branch 内的 commit 进一步原子化