Atomic Commits
Overview
Commit only the files touched for a single logical change. Always pass explicit paths to git commit and avoid blanket staging.
Workflow
- •Inspect state:
git status -sb,git diff,git diff --staged. - •Define the smallest logical change (one commit scope).
- •Commit only the files in that scope with explicit paths.
Commands
Tracked files only
code
git commit -m "<scoped message>" -- path/to/file1 path/to/file2
New files included
code
git restore --staged :/ && git add "path/to/file1" "path/to/file2" && git commit -m "<scoped message>" -- path/to/file1 path/to/file2
Guardrails
- •Never use
git commit -amorgit add .for atomic commits. - •Leave unrelated changes unstaged and uncommitted.
- •If a single file mixes concerns, split by hunks before committing.