DEV Community

Cover image for Atomic Commits
Diogo
Diogo

Posted on • Edited on

Atomic Commits

Why You Should Use Atomic Commits
If you've ever scrolled through a Git history and struggled to understand what changed and why, you're not alone. This is where atomic commits come in — a simple but powerful practice that can level up your workflow.

What Are Atomic Commits?
An atomic commit means that each commit is small, self-contained, and focused on a single purpose. It should answer:

“What is the smallest meaningful change I can make and commit right now?”

Instead of dumping multiple unrelated changes into one commit, you break them down into logical units — fixing a bug, adding a feature, or refactoring a method.

Why It Matters
Better Code Reviews: Smaller commits are easier to understand and review.

Easier Reverts: A single bad commit? No problem. You can safely roll it back without undoing unrelated changes.

Clearer History: Your Git log becomes readable and meaningful — like a story of your codebase.

Less Merge Hell: Smaller, isolated changes reduce merge conflicts.

Good vs Bad Examples
Bad Commit:

git commit -m "fix bugs and add new feature and update styles" 
Enter fullscreen mode Exit fullscreen mode

Atomic Commits:

git commit -m "fix: handle null values in user input" git commit -m "feat: add password visibility toggle" git commit -m "style: update button padding" 
Enter fullscreen mode Exit fullscreen mode

Tips for Writing Atomic Commits

  1. Stage changes selectively (git add -p)
  2. Use clear and consistent commit messages (e.g., conventional commits)
  3. Commit often, but with intention — each commit should have a purpose

Atomic commits take a bit more discipline, but they pay off quickly — especially in team environments. Clean history, fewer bugs, and better collaboration. Worth it.

Top comments (2)

Collapse
 
parizad profile image
Parizad

It was a great article. I write about Agile in my blog. I would be happy if you read my articles and write your comments about them.

Collapse
 
diogojlq profile image
Diogo

Thank you so much for taking the time to comment, i will for shure check out your articles. Thanks again.

Some comments may only be visible to logged-in visitors. Sign in to view all comments.