You have made a local commit and immediately remember a missing change. A soft reset in Git can move the branch back one commit while leaving the index and working files as they are. You can then add the missing work and make a new commit without rebuilding the staging area from scratch.
Git reset soft: inspect before moving HEAD
First, confirm where you are and what is already staged:
git status
git log --oneline -3
git diff --cached
git diff
Imagine the current branch points to commit B, whose parent is A. The index matches B, and the working tree is clean. The git soft reset operation below moves the current branch and HEAD back to A; it does not change the index or working tree. Git will now show the difference between A and the index as staged changes.
That clean starting point makes the example easy to follow. If other changes are already staged or unstaged, a Git reset using the soft mode leaves those contents in place too. The resulting staged diff is the entire difference between the new HEAD and the existing index, not necessarily just the changes from B. Review it before committing. A soft-mode reset in Git preserves an index that may already contain unrelated work, so inspect individual paths if the repository was not clean.
Undo the last local commit
On the branch whose last commit you want to redo, run:
git reset --soft HEAD~1
HEAD~1 names the first parent of the current commit. The command needs that parent to exist, so it does not work as written on a repository’s first commit. After the command, A is the current commit, while B is no longer the tip of this branch. The old commit object is not immediately deleted, and references such as the reflog can often help locate it.
The git reset soft workflow is useful when the last commit is local and you want to adjust its contents. Add the missing change with git add, inspect git diff --cached, and create a replacement commit with git commit. If you only need to change the most recent message or add changes to that commit, git commit --amend is another option; it also creates a replacement commit.
A git soft reset does not take a photograph of the working tree and then restore it. It changes the commit reference while keeping the index and files untouched. That distinction matters if you had edited a tracked file again after committing: the unstaged edit remains unstaged, and it may appear alongside the staged difference from the moved HEAD.
Follow the three states
Think of HEAD as the commit currently checked out, the index as the proposed next snapshot, and the working tree as the files you edit. Immediately before the example, all three reflect B. Immediately after the soft Git reset, HEAD reflects A, but the index and working files still reflect B. Consequently, the changes introduced between A and B appear staged.
Use git status to see staged and unstaged paths. git diff --cached compares the index with HEAD; git diff compares the working tree with the index. If a file appears in both comparisons, the staged version and the file on disk contain different edits. Inspect each before deciding what belongs in the next commit. A Git reset in soft mode leaves those two versions separate; staging the file again would update the index to match its current working-tree content.
The git reset soft method can also move to another commit, such as HEAD~2, when you intentionally want to combine work from more than one commit. Verify the target with git log first. For this git reset soft operation, also check that the commits you intend to replace are on the current branch and have not been shared. The index still stays as it was, so the staged result reflects the cumulative difference from that target, including any changes staged before the reset.
Compare mixed and hard resets
The mode determines what else Git updates when it moves the branch:
| Mode | HEAD and current branch | Index | Working tree |
|---|---|---|---|
--soft |
Move to target | Unchanged | Unchanged |
--mixed |
Move to target | Reset to target | Unchanged |
--hard |
Move to target | Reset to target | Reset to target for tracked paths |
A mixed reset is the default when no mode is given. In the clean example, git reset HEAD~1 moves to A and leaves the former commit’s changes in the working tree as unstaged edits. A soft reset of the Git branch instead keeps the index intact, so those changes appear staged.
A hard reset can discard tracked working-tree and staged changes, and it may overwrite or remove untracked paths that obstruct writing tracked files. Do not select it merely because you want to remove a commit from a branch. Check the target and protect any work you need first. The reflog may recover a former commit, but it is not a reliable backup of uncommitted edits.
Reset or revert shared work?
Reset moves a branch reference and changes which commits appear in that branch’s history. If B has already been shared, replacing it can complicate collaborators’ work and may require coordinated history rewriting. A revert instead creates a new commit that applies an inverse change while retaining the original commit in history.
For a straightforward non-merge commit, git revert <commit> is often appropriate for a shared branch. Review the resulting changes and tests: a revert can conflict or need follow-up adjustments, and reverting a merge requires choosing a parent. A git soft reset is most convenient for local history you control, not a substitute for agreeing on a team’s shared-history process.
Check the result
After a soft reset, Git status and both diff views show what is staged and what remains only in your files. Check the recent log as well, then commit only the changes you intend. If the commit is already shared, consider a revert and coordinate with the team before rewriting published history.
