Atomic Commits: One Logical Change
What You'll Learn
You'll learn why each commit should represent a single, focused change and how this practice makes code review, debugging, and reverting changes dramatically easier.
The Core Idea
An atomic commit contains exactly one logical change—nothing more, nothing less. Think of it like writing a book: each paragraph should express one complete thought. If you mix multiple ideas into one paragraph, readers get confused about what you're trying to say.
Similarly, a commit should do one thing well. Examples of atomic commits:
- Fix a specific bug
- Add one new function
- Update documentation for a single feature
- Refactor a single method
Non-atomic commits mix multiple changes: "Fix login bug AND update README AND refactor database helper." This creates problems.
Why Atomic Commits Matter
Code Review: Reviewers can understand and evaluate one change at a time. A commit titled "Fix password validation logic" is easy to review. A commit mixing password fixes, styling updates, and unrelated refactoring overwhelms reviewers.
Debugging: When something breaks, you can use git log to pinpoint exactly which logical change caused the problem. Mixed commits force you to mentally separate unrelated changes.
Reverting: If a feature causes issues, you can cleanly revert one atomic commit. With mixed commits, reverting means losing unrelated good changes too—or manually separating them.
The Analogy
Imagine grocery shopping where each bag contains one category: produce, dairy, meat. You can easily find items and return a bag if needed. Mixed bags make everything harder.
In Practice
Before committing, ask: "Does this commit do exactly one thing?" If you're using "and" in your commit message, you probably need multiple commits.
Key Takeaway: Atomic commits—one logical change per commit—make your Git history a clear, reviewable, and debuggable story of how your code evolved.