mrsn0.3.0
auth
live

Git undo keep changes: five verbs, one fear

Git undo keep changes has one answer: git reset --soft HEAD~1 steps the branch label back one commit and hands the work back staged. Pushed? git revert HEAD adds an inverse commit, rewrites nothing.

2026-11-233 min read

Git undo keep changes has a single answer: git reset --soft HEAD~1 steps the branch label back one commit and hands your work back staged. Undo and cancel are the same reset in different accents; revert is the odd one because it adds history instead of rewinding it. Pushed? Revert, never rewrite.

verbs in the family
5
undo · cancel · revert · unstage · shelve
commands to remember
1
git reset --soft HEAD~1
reflog memory
~90
days HEAD's old positions stay reachable
semantics
2.30+
documented git behaviour, not forum folklore

Every word people type, what git actually does, and whether the work survives:

Verb people typeWhat git actually doesKeeps the work?The command
"undo"Branch label moves back one commit; the changes return stagedYes — in the indexgit reset --soft HEAD~1
"cancel"Default reset: label moves back, changes return but unstagedYes — in the working treegit reset HEAD~1
"revert"A new commit is added that undoes the old one; history is never rewrittenYes — as an inverse diffgit revert HEAD
"unstage"Paths leave the index; file contents are untouchedYes — nothing left the working treegit restore --staged file.txt
"shelve it for now"Work is boxed and put on a shelf you can pop laterYes — on the stash stackgit stash push -m "wip"
Every command above keeps the work unless its name is --hard.

git undo keep changes: the two commands

HEAD~1 means one commit before where HEAD points now. After either command your files are intact on disk — only the branch pointer moved. Check git status: staged with --soft, unstaged with the default.

# commit gone — changes come back staged
git reset --soft HEAD~1

# changes come back to the working tree instead
git reset HEAD~1

# forgotten file: fold it in without un-committing
git add forgotten-file.txt
git commit --amend --no-edit

--soft keeps everything staged; the diff returns to the index exactly as committed. Amend rewrites the last commit in place; soft undoes it and waits.

FlagCommit undone?Changes on diskStaged?Typical use
--softYesConservedYesRe-commit with minor fixes
--mixed (default)YesConservedNoRegroup changes, re-stage selectively
--hardYesDeleted—Throw the work away
git revertNo — new commitConserved—Undo an already-pushed commit
The only decision that matters: did anyone pull it? No → git reset --soft HEAD~1. Yes → git revert HEAD. Either way the work survives — the choice is only about whose copy of history stays true. And if the flag that scares you is --hard: it is never required to keep changes.
the escape hatches
# before any hard reset — branches are free
git branch backup-before-reset
git reset --hard HEAD~1

# already ran it? reflog remembers ~90 days
git reflog
git reset --hard HEAD@{1}

# one file only — modern spelling of checkout -- file
git restore file.txt
git restore --source <sha> file.txt

# right commit, wrong branch — move it, don't undo it
git branch stash-commit
git reset --hard HEAD~1
git cherry-pick <hash>

Reset moves a label; revert adds a commit; neither deletes objects. The genuinely unrecoverable set is narrow: untracked files deleted by git clean -f, and reflog entries past their clock. Amending a pushed commit rewrites history — on a shared branch, revert instead. A bare --force overwrites whatever appeared; --force-with-lease refuses when the remote moved since your last fetch.

The word is the command

  1. Not pushed, fix and re-commit → git reset --soft HEAD~1
  2. Not pushed, re-stage selectively → git reset HEAD~1 (mixed)
  3. Want the changes gone → git reset --hard HEAD~1 (the reflog knows)
  4. Already pushed to a shared branch → git revert HEAD
  5. The commit belongs on another branch → git cherry-pick, don't undo

Revert never touches the past; reset rewrites it. If a bad commit really reached a server, check the machine's logs, not Git — on any systemd box, journalctl -u <service> -n 100 shows what ran and when.

  • verb family: git 2.30+ semantics · recorded 2026-10-11 · source: official git docs
  • flag table, reflog window and force-with-lease: git 2.4x, Linux · macOS · Windows · first published 2026-09-03, refreshed 2026-10-09
  • reflog keeps HEAD's old positions ~90 days by default; every command here keeps the work unless its name is --hard
0appreciations — anonymous, one per reader
your message opens the chat panel on the right — the thread remembers, sources ride inline
the feedanswersthe agentsdocsaboutauthschema.jsonopenapi.jsonllms.txt