HOWTO · Git
How to Use `git reset --soft`
Learn how git reset --soft moves a branch to an earlier commit while keeping the changes staged, then verify and safely continue the work.
On this page
Use git reset --soft <target> to move the current branch tip to an earlier commit while leaving the index and working tree unchanged. The changes introduced by the commits you moved past therefore remain staged, ready to review and commit again. This is useful when you want to combine recent commits or revise their messages without losing their content.
What git reset --soft changes
A soft reset changes the current branch’s HEAD and branch tip to the commit you name. It does not update the staging index or the files in your working tree. As a result, changes between the old tip and the target are staged relative to the new tip. The command affects the branch currently checked out; it does not move every branch that points to the old commit.
Always provide a target when you intend to move history. If you omit it, Git uses HEAD, so the branch does not move. Existing staged or unstaged work also remains in place. Review the staged diff afterward so you know exactly what a later commit will contain.
Choose the commit to reset to
Inspect recent history with git log --oneline. Choose the commit that should become the current branch tip, and confirm its subject or hash before running the reset. For example, HEAD~1 means the first parent of the current commit; it selects the previous commit on the current line of history. HEAD~2 selects two first-parent steps back. A named branch, tag, or commit hash can also identify a target.
The target is the commit to keep as the tip, not the commit to remove. Resetting to HEAD~1 moves the branch back by one commit and leaves the changes from the former tip staged. If the history is not linear, verify the target in the log rather than assuming that a numbered parent expression selects the commit you have in mind.
Reset commits while keeping changes staged
For a simple one-commit reset, first inspect the log, then run git reset --soft HEAD~1. To combine several recent commits, use the appropriate earlier target, such as git reset --soft HEAD~3. The index and working tree are preserved, so the changes from those commits are available together for a new commit.
Run this example:
work_dir="$(mktemp -d)"
trap 'rm -rf "$work_dir"' EXIT
cd "$work_dir"
git init -q
git config user.name "Example User"
git config user.email "example@example.com"
printf 'first version\n' > note.txt
git add note.txt
git commit -qm "Add note"
printf 'second version\n' > note.txt
git commit -qam "Update note"
git reset --soft HEAD~1
git status --short
The example exits successfully and prints M note.txt, confirming that the change remains staged after the soft reset.
Verify the staged changes
After resetting, use git status to confirm that the intended files are staged. Use git diff --cached to inspect the exact staged patch before making another commit. The --cached option compares the index with HEAD, which is now the selected target. If the displayed changes are not the ones you intended, pause and inspect the target and the diff before committing.
When the staged patch is correct, create a replacement commit with git commit -m "Describe the combined change". To update the most recent commit instead, git commit --amend replaces it; check the staged content and commit message carefully before confirming. A soft reset does not automatically create a new commit or change commit messages.
How --soft compares with --mixed and --hard
All three reset modes move the current branch tip to the target, but they handle the index and working tree differently:
git reset --soft <target>moves the branch tip and leaves both the index and working tree unchanged. The affected committed changes remain staged.git reset --mixed <target>moves the branch tip and updates the index to match the target, while leaving the working tree files unchanged. Changes from the commits moved past become unstaged.--mixedis the default mode when no mode is specified.git reset --hard <target>moves the branch tip and makes both the index and tracked working tree files match the target. Tracked edits that are not in the target can be discarded, so use this only when that result is intended.
Reset modes generally leave unrelated untracked files alone. However, git reset --hard may delete an untracked file or directory if it obstructs writing a tracked path from the target. Choose --soft when you need the changes staged for a replacement commit; choose --mixed when you want to review them as unstaged work. Do not use --hard as a substitute for soft reset.
When to use git reset --soft safely
Soft reset is suited to editing recent local history, such as combining several commits into one or preparing their changes for a different commit. Before running it, confirm the current branch and target with git status and git log --oneline. Afterward, inspect git status and git diff --cached before committing so unrelated staged work is not included by mistake.
If the commits have already been shared, moving the branch rewrites the history other people may have based work on. Coordinate before changing shared history; for a public change that should be reversed while preserving history, a revert is generally a better fit. A soft reset changes only the local repository until you later push, but pushing rewritten history can disrupt collaborators. Keep the target and staged diff clear, and avoid force-pushing as a routine follow-up.