linuxlab.io
Tutorials▾
  • Linux & networking
    File system, processes, TCP/IP, BGP and OSPF
    →
  • Terraform & IaC
    HCL, state, plan/apply on a LocalStack sandbox
    →
  • Git & GitHub
    Object model, plumbing, branching, GitHub Actions
    →
All tutorials →
PricingAboutSign inCreate account
/
Intro
Lessons
Footer
linuxlab-TutorialsPricingAboutPrivacy & cookies
Copyright © 2026 LinuxLab. All rights reserved.
linuxlab.io
Tutorials▾
  • Linux & networking
    File system, processes, TCP/IP, BGP and OSPF
    →
  • Terraform & IaC
    HCL, state, plan/apply on a LocalStack sandbox
    →
  • Git & GitHub
    Object model, plumbing, branching, GitHub Actions
    →
All tutorials →
PricingAboutSign inCreate account
/
  • Introduction
  • Chapters
  • How it works
  • Lessons
  • Knowledge base
  • Interview prep
home/git/kb/Everyday workflow/atomic-commit

kb/workflow ── Everyday workflow ── intermediate

Atomic Commit

A commit that makes one logically complete change. Every atomic commit can be safely reverted, and the build and tests pass on every one. This is the foundation of a healthy Git history.

view as markdownaka: atomic, small-commit

"Atomic" in the context of commits means: one batch of changes, one topic, one goal. Not "fixed a bug + renamed a variable + updated react-router".

Rules

  1. One logical change, one commit. If the message needs the word "and", you probably have two commits.
  2. The build passes on every commit. git bisect depends on this.
  3. The commit is reversible via revert. No side effects.
  4. No "WIP", "fix typo", "addresses comments" in the public history. Squash these before a PR using interactive-rebase.

Why it matters

  • git bisect localizes a regression in log(N) steps. Broken commits in the history confuse bisect.
  • git revert <sha> cleanly undoes one feature. If a commit covers three topics, innocent changes get rolled back too.
  • git blame helps you understand the context of a change. A commit that "touched everything" provides no context.
  • Code review is much faster. One atomic commit is one thought to review.

What "atomic" does NOT mean

  • Not "small". A large refactor touching 30 files in a single commit is fine, as long as every change belongs to the same topic.
  • Not "one file". A file and a logical change are different axes. One topic may touch many files.
  • Not "written in one sitting". Atomicity is about the final shape of the commit, not the writing process. Write freely first, then use interactive-rebase and git add -p to compose atomic commits.

How to split an accumulated edit

The fastest approach is git add -p:

bash
git add -p src/auth/
git commit -m "feat(auth): add OAuth provider"
git add -p src/billing/
git commit -m "fix(billing): handle null currency"
git add -p src/utils/
git commit -m "refactor(utils): extract date helpers"

You pick hunks that belong to the current commit. The rest goes into the next ones.

If changes are interleaved within a file, Git splits them into hunks automatically. When the automatic split is wrong, use s (split) or e (edit) in patch mode.

Pitfalls

  • Perfectionism gets in the way. Atomicity is a convenience, not a religion. If splitting will take an hour for a one-line fix, skip it. Use judgment.
  • Atomic does not mean many tiny commits. Ten pick / squash / fixup entries in reflog is a normal working style. One clean commit lands on main.

§ команды

bash
git add -p

Interactive hunk-by-hunk staging: the primary tool for atomicity

bash
git commit --fixup=<sha>

Create a commit that will be merged with the given one via autosquash rebase

bash
git rebase -i --autosquash main

Auto-apply all fixup commits

§ см. также

  • commit-cmdgit commitCaptures what is in the index as a new commit object and moves the current branch to that commit. Without arguments it opens an editor for the message; the most common form uses `-m`.
  • addgit addMoves file changes from the working tree into the index (staging area). Does not commit anything. It only controls what goes into the next commit.
  • interactive-rebaseInteractive rebase`git rebase -i <base>` opens an editor with the list of commits from `<base>` to HEAD, where you can rename, combine, delete, and reorder them. It is the primary tool for cleaning up local history.
  • amendgit commit --amendRewrites the last commit: changes the message, folds in forgotten edits, or updates the content. Creates a new object with a new SHA. Safe before push; dangerous after.
Footer
linuxlab-
Copyright © 2026 LinuxLab. All rights reserved.
Tutorials
Pricing
About
Privacy & cookies