Skip to Content
sudocs

Undoing things

reset, restore, revert — how to get out of a mess

undoing things

git reset --hard HEAD~1

nukes the last commit and all its changes. gone. use with caution.

git reset --soft HEAD~1

removes the last commit but keeps the changes staged. useful if you committed too early and want to rework things.

git restore src/some-file.ts

discards unstaged changes to a file. brings it back to what it was at HEAD. can't undo this so be sure.

git restore --staged src/some-file.ts

unstages a file without throwing away your changes. it's just removed from the upcoming commit.

git revert abc1234

creates a new commit that undoes a previous one. this is the safe option if the commit has already been pushed to a shared branch — it doesn't rewrite history.

On this page