mrsaynothing.dev
git undo, cancel, revert — keep the changes every time

> git undo, cancel, revert — keep the changes every time▋

Every keep-changes query on our own search board — undo, cancel, revert — answered on one page: the command per mess, the --hard trap, and reflog as the net.

mrsaynothing· 11 October 2026· 7 min read

✦ fixgit reset --soft HEAD~1

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 of itself.

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, growing +100% week over week, and it brought four spelled-differently cousins with it. People are not confused about git. They are afraid of --hard, and every generic tutorial answers the fear with the one flag that confirms it. This page works the family top to bottom: pick your verb, check the table, and only then touch history.

all reset revert restore stash
Verb people type What git actually does Keeps the work? The command
"undo" Branch label moves back one commit; the changes return staged Yes — in the index git reset --soft HEAD~1
"cancel" Default reset: label moves back, changes return but unstaged Yes — in the working tree git reset HEAD~1
"revert" A new commit is added that undoes the old one; history is never rewritten Yes — as an inverse diff git revert HEAD
"unstage" Paths leave the index; file contents are untouched Yes — nothing left the working tree git restore --staged file.txt
"shelve it for now" Work is boxed and put on a shelf you can pop later Yes — on the stash stack git stash push -m "wip"

The only decision that matters

a commit you regret? start here yes — someone pulled it no — it is still yours git revert HEAD history grows an inverse commit — nothing anyone pulled is rewritten git reset --soft HEAD~1 the label steps back, your work returns staged the bad change is cancelled by public, additive history re-commit it properly same work, better message or split
fig 1 — pushed or not pushed: the one question that picks the verb. Both roads keep the work; the undo-generator below takes the whole mess as input.

How do I undo my last commit and keep the changes?

git reset --soft HEAD~1 — the branch label steps back one commit and everything you did comes back staged. Nothing is deleted, nothing leaves the index; you are free to re-commit with a better message or split the work. The full walkthrough, including the pushed case, is in git undo last commit: keep changes, stay safe.

verify: after the reset, git status should show your files staged under "Changes to be committed" — that is your work, handed back.

Does "git undo commit keep changes" mean something different?

No — same question, same answer. "Undo" has never been a git command; our board shows both spellings aimed at identical problems, and both resolve to reset --soft. When people say undo, they mean move the label, keep the work — which is the only thing a soft reset has ever done.

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 is automatic, since the bad commit stays in the record and the working tree ends up without it. It is the right tool the moment anyone else has pulled; the reset-vs-revert fork is mapped in git revert vs reset: which one saves your history?

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 from the same week on our board — both land on git reset --soft HEAD~1. Git only cares about the label you move and the flag you pass; the vocabulary is yours to bring.

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 — the one keep-nothing verb on this page. If the commit was never yours to begin with and nothing references it, git gc is what eventually collects it, not you.

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. The single-file edge cases — including why the stash survives a checkout — live in git stash a single file without losing the rest.

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. The conflict playbook for the messy ranges is in git cherry pick: multiple commits, branches, conflicts.

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 — expect conflicts where the branches diverged, and take them one at a time rather than in bulk.

Can I get a dropped commit back?

Almost always yes — the reflog remembers where HEAD has been for about 90 days by default (git's gc.reflogExpire). Find the dropped hash with git reflog, then git reset --soft HEAD@{1} to put it back under your working tree. You are not undoing anything — you are moving a label while git quietly keeps the receipts.

Which git undo should I use?

The table above, honestly — but if you want the machine to pick: the git-undo generator takes your mess as input and prints the exact command, and its launch post shows the reasoning per case. Every recovery this cluster has tested is shelved on the git-undo hub.

The trap in the room: --soft, --mixed, --hard

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 target commit and discards the rest. If you have already typed --hard in panic: the reflog still has the commit for ~90 days — git reflog, then reset back to the hash. The verb you type in the first five seconds decides nothing forever; git's diary is longer than your regret.

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. The board says most of you typed undo — the data was here before the advice was.

$ Share this post

$ Get the next how-to by email

One email per post. Fix it and move on.

self-hosted · no third parties · one-click unsubscribe

One email, weekly digest. Zero pixels.

what is this?