One command answers the whole family: git reset --soft HEAD~1 steps the branch label back one commit and hands your work back staged.
Undo, cancel, revert are not three git features. Two of them are the same reset in different accents; revert is the odd one out because it adds history instead of rewinding it. And already pushed? Revert, never rewrite — anyone who pulled is holding the old commits.
Every question below is a real query from our site's search ledger — the keep-changes family is one of the busiest clusters on the board, and every spelling of it is featured here.
The short answer
git reset --soft HEAD~1
git reset --soft HEAD~1 is the answer to every keep-changes spelling: the branch label steps back one commit and your work comes back staged, ready to re-commit. Verify: after the reset, git status should show your files staged under "Changes to be committed" — that is your work, handed back.
Tested on: git 2.30+ semantics · record: official git docs + our search ledger.
Git ships five verbs for getting your code back — undo, cancel, revert, reset, restore — and not one of them is actually called undo. Somewhere, a thesaurus is very proud.
Here is what the thesaurus costs. Last week the head query in this family — git undo last commit keep changes — pulled 73 impressions at position 11.1 with zero clicks, despite a full post about the exact job. The words were all there; the page just wasn't answering the whole family in one place. Now it does.
The only decision that matters
Before any verb: has anyone else pulled the commit?
-
yes →
git revert HEAD— history grows an inverse commit, nothing anyone pulled is rewritten -
no →
git reset --soft HEAD~1— the label steps back, your work comes back staged
Does "git undo commit keep changes" mean something different?
No — same question, same answer. "Undo" has never been a git command; the board shows both spellings aimed at identical problems, and both resolve to reset --soft.
Why does "git revert last commit keep changes" get a different answer?
Because revert is the only family member that adds history instead of rewinding it. git revert HEAD creates a new commit whose diff undoes the old one — the "keep changes" part works differently: your original commit stays in history, and the revert rides on top. Revert = public undo. It never rewrites what anyone already has; it cancels the change with a new, additive commit.
Is "git cancel commit" a real command?
No — cancel is plain speech, and git's plain-speech translation is reset. "Cancel commit but keep changes" and "cancel last commit but keep changes" — two more spellings, same reset --soft.
Can I delete a commit nobody has pulled?
Yes — an unpushed commit is still yours to reshape without consequences. reset --soft keeps the work, reset HEAD~1 keeps it unstaged, and only --hard throws it away.
Can you git stash a single file?
Yes — git stash push -m "wip" -- src/app.ts shelves one path and leaves the rest of your tree alone. The -- separator is what scopes the stash to named paths.
Can I cherry-pick multiple commits?
Yes — a range: git cherry-pick A^..B takes every commit after A up to and including B, in order. Add -n if you want them staged as one lump instead of committed one by one.
How do I cherry-pick multiple commits from another branch?
The same range form works across branches: git switch target && git cherry-pick A^..B. Git resolves the commits from the source branch and replays them onto yours.
Can I get a dropped commit back?
Almost always yes — the reflog remembers where HEAD has been for about 90 days by default. Find the dropped hash with git reflog, then git reset --hard <hash> to walk back to it.
Which git undo should I use?
The decision above, honestly — and if you want the machine to pick, the git-undo generator on the site takes your mess as input and prints the exact command.
One flag decides everything. The flag decides where your work lands, and only one of the three is dangerous: --soft returns it staged, --mixed (the default) returns it unstaged, --hard matches everything to the old commit and your uncommitted work is gone.
Which spelling brought you here — undo, cancel, or revert? Say it in the comments; the generator takes all three, and the strangest one becomes the next post.
Top comments (1)
The honest numbers behind this one: the head spelling sat at position 11 with 73 impressions and zero clicks for a week while three separate posts each owned a slice of the family. The hub bet is that one page answering undo, cancel AND revert beats three pages each answering one — d7 will tell. If you arrived on a spelling I missed, that is literally the next post.
Some comments may only be visible to logged-in visitors. Sign in to view all comments.