Undo, Restore, Reset, and Revert

Summary

This note explains the main ways Git can undo or roll back work. The goal is not to memorise every command immediately, but to build a safe mental model for when to use restore, reset, and revert, and when to slow down before changing history.

Git reset workflow diagram from the official Git Book

Official Git diagram showing how reset moves through working tree, index, and commit history layers.

Why this matters

  • Git gives you several ways to undo work, but they do not all mean the same thing
  • many beginner mistakes come from using reset when restore or revert would have been safer
  • understanding safe vs destructive undo is important before working in shared repositories

Environment / Scope

ItemValue
Topicundo and rollback in Git
Best use for this notechoosing the right undo tool
Main focusworking tree, staging area, commit history
Safe to practise?yes, in a throwaway repository

Key concepts

  • Restore - undo changes in files or in the staging area without rewriting branch history
  • Reset - move branch state, often used to unstage or rewrite local history
  • Revert - create a new commit that reverses an earlier commit
  • History rewrite - changing commit history instead of adding a corrective commit

Mental model

Think about three layers:

working tree
staging area
commit history

Different Git commands affect different layers:

Command familyMain effect
git restoreworking tree and staging area
git resetstaging area and sometimes branch history
git revertcommit history by adding a new reversing commit

Everyday workflow

SituationSafer first choiceWhy
You changed a file and want to discard the editgit restore <file>removes uncommitted file changes
You staged something by accidentgit restore --staged <file>unstages without touching history
You want to undo a shared bad commitgit revert <commit>keeps history honest and safe for collaboration
You want to rewrite a local commit you have not shared yetgit resetuseful locally, but riskier once pushed

Common misunderstandings

MisunderstandingBetter explanation
reset is just another word for undo”reset can rewrite history, so it can be much more destructive
revert deletes the bad commit”revert adds a new commit that reverses the old one
restore is only for advanced users”restore is often the safest everyday command for file-level undo
”If I already pushed it, I should still just reset”in shared history, revert is often the safer choice

Verification

CheckExpected result
git statusclearly shows whether files are modified or staged
git log --onelineshows whether a new revert commit was created
git diffshows working tree changes
git diff --stagedshows staged changes

Pitfalls / Troubleshooting

ProblemLikely causeWhat to check
File changes disappeared unexpectedlyused restore on the wrong filegit status, recent command history
Commit history changed in a confusing wayused reset without clear intentgit log --oneline --graph --all
Shared branch became messylocal history rewrite after pushwhether branch was already pushed or shared
Undo choice feels unsafeweak mental model of the three layersworking tree vs staging vs history

Practical rule

If the commit is already shared, pause before using reset. In collaborative work, revert is usually easier to explain and safer to recover from.

Key takeaways

  • restore is often the safest way to undo file-level changes
  • reset is powerful, but easier to misuse because it can rewrite local history
  • revert is usually the safest way to undo already shared commits

Official documentation