Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

An atomic Git commit captures one coherent, reviewable idea—not every change currently in your working tree. Git’s index (also called the staging area) lets you choose exactly what goes into a commit, including individual lines from a file. You can split mixed changes into separate commits and repair local history, but changing commits that have already been shared can disrupt collaborators.

What is an atomic commit in Git?

An atomic commit is a logical, self-contained change that expresses one specific purpose. The Git project guide puts it this way: “Commits should be logical, atomic units of change that represent a specific idea.” GitHub’s Git commit guide

Atomicity is about meaning, not file count. A commit may touch several files if they all contribute to the same change; a single file may need to be split across multiple commits if it contains unrelated work. A focused history helps a reviewer understand what changed and why, and makes individual changes easier to inspect or isolate later.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How does Git decide what goes into a commit?

Git commits the contents of the index, not automatically every edit in your working tree. Think of three states: the last committed snapshot, your working-tree files, and the index where you assemble the next snapshot. The git-commit reference documents this behavior.

That separation means you can leave unrelated work untouched while staging a focused change. Git’s user manual describes patches as a way to select logical changes. Git user manual

How to make an atomic commit

  1. Check the branch and working tree with git status. Review the changes with git diff so you know what is modified before staging.

  2. Stage the complete files that belong to one purpose with git add path/to/file. To stage only selected portions, use git add --patch path/to/file. You can also select hunks while committing with git commit --patch.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  3. Inspect what is staged with git diff --cached. This is the key check: it shows the snapshot the next commit will record. Add missing pieces or unstage unrelated ones before proceeding.

  4. Create the commit with a concise message describing the purpose of the change: git commit -m "Describe the focused change". Git’s command reference also documents --dry-run as a way to preview what would be included.

git commit -a is not a substitute for reviewing the index: it stages modifications and deletions of tracked files, but does not add new, untracked files. GitHub’s Git commit guide

How to commit only part of a file

Use patch mode when a file contains both the change you want to commit and other work you need to keep separate. Run git add --patch path/to/file; Git presents change hunks and lets you choose which to stage. Then inspect the result with git diff --cached and commit the selected portion. The remaining edits stay in your working tree.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If a hunk combines lines that belong to different concerns, patch mode offers options for splitting or editing hunks where possible. Review the staged diff carefully afterward: the goal is a commit that represents the intended change without accidentally omitting a necessary line or including unrelated work.

How to split a commit that mixes separate changes

If the changes are still uncommitted, unstage them if needed, then stage one coherent slice at a time. Create a commit for that slice, stage the next slice, and commit it separately. For example, a bug fix and an unrelated documentation update are usually clearer as separate commits when each has its own purpose.

If the mixed changes are already committed locally, use interactive rebase to edit or divide the commit. The Git user manual documents interactive rebase, and GitHub’s guide explains the collaborative implications of rewriting history. Git user manual GitHub Docs: About Git rebase

  1. Start an interactive rebase covering the commit you want to change and any commits after it, for example: git rebase -i HEAD~3. Choose a range that includes the target commit.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  2. In the todo list, change pick to edit beside the commit you want to split, then save and close the editor.

  3. When Git stops, undo that commit while keeping its changes in the working tree with git reset HEAD^.

  4. Stage and commit the first coherent slice, then stage and commit the next slice or slices. Use patch staging if a file contains multiple concerns.

  5. Continue the rebase with git rebase --continue. Resolve any conflicts that arise, stage the resolved files, and continue again as needed.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Interactive rebase rewrites commits from the selected point onward. Use it on a branch you control or coordinate with anyone who may depend on that branch.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

How to fix the latest commit

For a correction to the tip commit, use git commit --amend. First stage the correction, then run git commit --amend to replace the latest commit. You can also use git commit --amend -m "Corrected message" to replace its message. Git documents amend as replacing the tip commit, rather than adding an ordinary new commit. The git-commit reference

Amend is appropriate for work that belongs in the latest commit, such as correcting its message or adding a missing change. It changes commit history, so do not treat it as harmless once that commit has been published.

How to combine local commits with fixup and autosquash

When you have already made a small follow-up commit for an earlier local commit, you can mark it as a fixup and fold it into its target. Create the fixup with git commit --fixup=<target>, then start an interactive rebase with autosquash, such as git rebase -i --autosquash HEAD~4. Adjust the range to include both the target and fixup commits. Git places the fixup beside its target in the rebase todo list so it can be folded in.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

An amend-style fixup can also replace the target commit’s message when autosquashed. Use fixup and autosquash to remove intermediate commits that do not have independent value; keep separate commits when each records a meaningful step.

Is it safe to amend or rebase after pushing?

Rewriting a commit changes the sequence other people may already have fetched. GitHub advises against rebasing commits that have already been pushed as a general practice. GitHub Docs: About Git rebase

Before rewriting shared history, check the branch’s review and collaboration conventions and coordinate with contributors. Do not force-push blindly: if a team agrees a published branch must be rewritten, follow its procedure so collaborators can reconcile their local histories. When the commit is already shared and a correction is needed, adding a new corrective commit often avoids changing the shared sequence.

Choose separate commits, a squash, or a history edit

Situation Approach Why
Two changes have distinct purposes and are not yet committed Stage and commit them separately Each commit remains focused and independently reviewable.
Several local intermediate commits do not carry independent value Use interactive rebase with squash or fixup; autosquash can arrange fixups The final history can retain the meaningful change without noisy steps.
The latest local commit needs a correction or message change Use git commit --amend It replaces the tip commit directly.
A commit that others may have fetched needs revision Coordinate before rewriting; consider a new corrective commit Changing published history can disrupt collaborators.

Make the choice by asking whether each commit has one understandable purpose, whether its result can be reviewed or tested, and whether the branch has been shared. The right workflow depends on the branch and team conventions; no single history style fits every project.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.