/commands/git/git-reset-soft-head-1
git reset --soft HEAD~1: undo the last commit, keep the changes
verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · git version 2.55.0.windows.5updated 2026-10-20
- tool
- Git
- versions
- Git 2.x
- os
- linux, macos, windows
git reset --soft HEAD~1 removes the most recent commit from the current branch and leaves all its changes staged, ready to be committed again. Use it to fix a commit message, add a forgotten file, or split the commit.
Undo the last commit
git init -q -b main repo && cd repo
echo one > a.txt && git add a.txt && git commit -qm "first"
echo two > b.txt && git add b.txt && git commit -qm "second (wrong)"
git log --oneline
git reset --soft HEAD~1
git log --oneline
git status --shortOutput
6164400 second (wrong) 6a05283 first 6a05283 first A b.txt
b.txt is still staged (A), so git commit -m "second" recreates the commit the way you want it.
--soft vs --mixed vs --hard
| Mode | Branch moves | Index (staging) | Working tree |
|---|---|---|---|
| --soft | yes | kept: changes stay staged | kept |
| --mixed (default) | yes | reset: changes become unstaged | kept |
| --hard | yes | reset | reset: uncommitted changes are deleted |
Undo the undo
The old commit is still reachable through the reflog for a while (90 days by default):
git init -q -b main repo && cd repo
echo one > a.txt && git add a.txt && git commit -qm "first"
echo two > b.txt && git add b.txt && git commit -qm "second"
git reset -q --soft HEAD~1
git reset -q --soft 'HEAD@{1}'
git log --onelineOutput
5f2f41b second 6a05283 first
Sources
Related pages
flags · gitgit push --force-with-lease: a safer force push--force-with-lease overwrites the remote branch only if it still points where your remote-tracking ref says, so commits pushed since your fetch are never lost.cheat sheets · gitGit cheat sheet: everyday commandsGit cheat sheet: setup, stage and commit, branches with switch, history, undo with restore, reset and revert, stash, remotes, tags and the reflog on one page.glossary · gitWhat is a detached HEAD in Git?Detached HEAD means HEAD points at a commit instead of a branch, after checking out a tag or a hash. New commits there belong to no branch until you create one.