An atomic Git commit captures one coherent, reviewable idea—not every change currently in your working tree. Use the index to choose what goes into the next commit, inspect that selection, and then commit it. If a local commit combines unrelated work, split or reorganize it; if it has already been shared, coordinate before rewriting it.
What makes a Git commit atomic?
An atomic commit is a logical, reviewable unit of change with a specific purpose. The Git project guide puts it this way: “Commits should be logical, atomic units of change that represent a specific idea.” A commit might, for example, add one validation rule or fix one bug; unrelated formatting changes belong in a separate commit if they have an independent purpose.
As an Amazon Associate I earn from qualifying purchases.
Git builds a commit from the index, also called the staging area. Your working tree can contain other edits that are not staged, so a plain git commit does not automatically include every uncommitted change. That separation is what lets you assemble a focused commit from a larger set of edits.
How to create a focused commit
-
Check your branch and working-tree state with
git status. Inspect the unstaged changes withgit diff.#1 Best Overall
-
Stage the files that belong to one purpose:
git add path/to/file. To select only parts of a file, rungit add --patch path/to/file(orgit add -p path/to/file) and respond to the prompts for each change hunk. -
Review exactly what is staged with
git diff --cached. If you staged a change by mistake, adjust the index before committing; for example, usegit restore --staged path/to/fileto unstage a file without discarding its working-tree edits. -
Commit with a concise message that says what the change accomplishes:
git commit -m "Validate input before saving". Git’s--dry-runoption can preview what a commit would include:git commit --dry-run.Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.Rank #2
You can also use git commit --patch to select hunks for a commit interactively. For routine work, explicitly staging hunks and checking git diff --cached makes the boundary of the commit easy to verify.
How to handle common staging cases
Several unrelated changes are in one file
Use git add --patch path/to/file to stage only the hunks that serve the first purpose. Review and commit them, then stage the remaining hunks for another commit. If a single hunk contains both concerns, the interactive patch prompt offers options to split it when Git can divide it; otherwise, edit the change so the concerns can be staged separately, taking care not to lose either edit.
Tracked files and new files
git add -A stages additions, modifications, and deletions across the working tree. By contrast, git commit -a stages modifications and deletions of already tracked files as part of the commit, but does not add new, untracked files. If you are aiming for an atomic commit, check git status and inspect the staged diff rather than relying on either shortcut to choose the right purpose for you.
How to split a commit that already exists locally
If the mixed commit is the latest commit and has not been shared, the most direct approach is to undo that commit while keeping its changes in your working tree, then stage and commit each coherent slice:
Free tools Windows power users keep installed
One-click scans. No signup required.
-
Run
git reset HEAD^. This removes the tip commit from the current branch and leaves its changes in the working tree, unstaged. -
Use
git add --patch(or stage whole files withgit add path/to/file) to assemble the first coherent slice. Review it withgit diff --cached, then commit it. -
Stage and commit the remaining changes as one or more separate units. Use
git statusandgit diffto check that no intended changes were left behind.
For an older local commit, start an interactive rebase that includes it, such as git rebase -i HEAD~3 when the target is among the last three commits. In the todo list, change pick to edit for the target commit, save and close the editor, then run git reset HEAD^. Stage and commit the separate slices, and finish with git rebase --continue. Resolve any conflicts Git reports before continuing. Choose a range that includes the target commit; do not include commits you do not intend to rewrite.
How to fix or combine local commits
Correct the latest commit
For a small correction to the tip commit, stage the intended change and run git commit --amend. Git replaces the tip commit rather than adding a second one. The command can update the commit contents, its message, or both.
Best Value
Combine intermediate steps
During git rebase -i, mark a later commit as squash to combine it with the preceding commit and edit the resulting message, or as fixup to combine it while discarding the later commit’s message. Fixup commits can also be created with git commit --fixup=<target> and arranged next to their targets by running git rebase --autosquash -i <base>. Autosquash prepares the rebase todo list; review it before proceeding.
Keep separate commits when each records a useful, understandable step. Squash intermediate work when it is merely cleanup for a single purpose and does not need to stand alone in the history.
When is rewriting a commit safe?
Amending, resetting, and rebasing change the commit sequence. They are straightforwardest when the affected commits exist only on a branch you control. Once a commit has been pushed and others may have based work on it, rewriting can leave collaborators with a different history to reconcile. GitHub’s guidance cautions against rebasing already-pushed commits as a general practice.
Recommended Free Tools
-
Local, unpublished branch: amend or rebase to make the history clearer, after checking the commits in the range.
-
Shared or reviewed branch: coordinate with the people using it and follow the team’s review and branch conventions before changing published history.
-
Already pushed: do not force-push reflexively. Agree on the recovery plan first; a new corrective commit may be less disruptive than replacing the shared commit.
Quick Recap
Bestseller No. 1SaleBestseller No. 4
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.




