A teammate once answered “git reset —hard” to every undo question the way other people answer “turn it off and on again”. It worked twice. The third time took a Friday afternoon and a reflog lesson nobody enjoyed. This site’s Undo Anything in Git hub grew out of that week — and today it gets a proper tool.
The git undo generator is live: three questions in, one exact command out. No account, no upload — everything runs in your browser. Pick whether the commit was pushed, whether you keep the changes, and whether anyone else pulls the branch; it prints the right git reset, git revert or reflog rescue, with a warning where the command bites.
Why build a tool for four commands?
Because the search data says people want the answer, not the essay. Google Search Console shows this site ranking for “git reset last commit keep changes” at position 12.3 — 27 impressions in one week, zero clicks. The query is a cry for a command, and the searcher scrolls past anything that makes them read. A generator answers in one screen.
The same pattern repeats across every variant: “and keep changes”, “but keep changes”, “keep the file”. People aren’t researching version control theory. They have a mess, right now, and they want the shortest path out of it.
How the generator decides
Three questions, straight from the revert-vs-reset decision guide:
- Where is the commit? Unpushed, pushed, or lost entirely.
- What happens to the changes? Keep them staged, keep them unstaged, or discard them.
- Who else pulls this branch? The question that separates a clean rewrite from a team incident.
The shared-branch question is the whole tool. Everything else is convenience; that one is damage control.
Its answers, in full:
| Command | History | Working tree | Shared branch? |
|---|---|---|---|
git reset --soft HEAD~1 | moves back 1 | changes kept, staged | no — rewrite |
git reset HEAD~1 | moves back 1 | changes kept, unstaged | no — rewrite |
git reset --hard HEAD~1 | moves back 1 | changes discarded | no — destructive |
git revert HEAD | adds an undo commit | untouched | yes — the safe move |
git reflog + git switch -c recovery <sha> | nothing lost | restored from reflog | rescue after anything |
The commands it prints
Every case the generator covers, in copy-paste form:
# committed, not pushed, keep the changes staged
git reset --soft HEAD~1
# committed, not pushed, keep the changes unstaged
git reset HEAD~1
# pushed, others pull this branch — the only polite undo
git revert --no-edit HEAD~1..HEAD
git push
# committed and lost — reflog knows for ~90 days
git reflog
git switch -c recovery <sha-from-the-list> The HEAD~1..HEAD range form reverts exactly the commits you name without recreating them one by one — worth knowing even if the tool types it for you.
Under the hood
The logic is a decision table, not magic. Three questions give eighteen combinations; most collapse into the same handful of commands, because “unpushed + discard” and “pushed + my own branch + discard” differ only in the force-with-lease tail. The page ships as one static route — no server, no analytics, no cookies — so it loads on a phone in a server room, which is where most git emergencies happen, and the copy button hands you the exact block including the warning comments.
What it deliberately doesn’t do
No interactive rebase help — if you’re reordering commits, you already know more than the tool teaches. No stash surgery; that has its own guide. And it refuses to guess: when the situation is “pushed to a shared branch”, the only command it offers is revert, because the alternatives burn teams. The long-form guide on undoing a commit explains what each flag does to the reflog; the tool just refuses to let you pick the wrong one at speed.
The source is at github.com/mrsaynothing/git-undo — plain HTML and JavaScript, no build step, no dependencies. Fork it, restyle it, rip out my wording. The version on this site runs the same logic as a static SvelteKit page.
If it saves you one reflog session this year, it has paid for the afternoon it took. If it gives the wrong answer for a case you hit, that’s what the repository issues are for.
FAQ
What does the git undo generator do?
It asks three questions — was the commit pushed, do you keep the changes, does anyone else pull the branch — and prints the exact git command: reset, revert, or a reflog rescue.
Is git reset --hard safe?
On commits you never pushed, yes — the dropped work stays reachable through git reflog for roughly 90 days. On shared branches, never: revert instead.
Do I need an account for the tool?
No. It is a static page that runs entirely in your browser — nothing is uploaded, nothing is logged.
— mrsaynothing
— mrsaynothing
Builds, breakages, and what actually shipped.
Discuss this post on dev.to dev.to ↗
Get the next build log by email
One email per post. Receipts and mistakes included.
what is this?My Agent Shipped a Post I Gated. It Stayed Live for a Day.
Enjoying the write-ups? I build like this for a living. get the newsletter