Git Undo Lab: Reset, Revert, Restore, and Reflog

Understand the difference between git restore, git reset --soft, git reset --mixed, git reset --hard, git revert, and git reflog. The safe undo lab shows how each command changes the working tree, staging area, branch pointer, and commit history.

Use git revert for a public history-preserving undo, and learn when reset or reflog is appropriate for local recovery.

Complete Git Undo Comparison

CommandTypeSafetyDescriptionWorking DirectoryIndexHistoryWarning
git restore <file>Working Tree UndoCautionDiscards unstaged modifications in the working directory, restoring the file to match the index/HEAD.Discards unstaged editsUnchangedPreserved (no new commit)Destructive for unstaged edits! Edits made in the working tree that were never staged will be lost permanently.
git restore --staged <file>Unstage from IndexSafeUnstages a file from the Index back to the working directory without losing any edits.Preserves your edits in working directoryClears staged version back to HEADPreserved
git reset --soft HEAD~1Undo Commit (Keep Staged)SafeMoves branch pointer back by 1 commit. Leaves all changes staged in the Index ready to re-commit.Completely preservedChanges remain staged in indexRewrites branch tip (reflog keeps old hash)Safe locally. If the commit was already pushed to a shared remote, rewriting the branch tip can cause sync issues for teammates.
git reset [--mixed] HEAD~1Undo Commit (Keep Unstaged)SafeMoves branch pointer back and un-stages files from Index. All changes are kept as unstaged files in your working directory.Preserved as unstaged filesReset to match HEAD~1Rewrites branch tipYour changes are not lost; they are kept unstaged in your working directory.
git reset --hard HEAD~1Nuclear ResetDestructiveMoves branch pointer back AND forcibly overwrites both Index and Working Directory to match HEAD~1.Discarded permanentlyDiscarded permanentlyRewrites branch tipHigh risk: All uncommitted modifications in your working directory and staging area will be permanently destroyed. Committed work can only be recovered via reflog.
git revert <commit>Safe Public History UndoSafestCreates a brand-new commit that inverts the changes of the target commit. Does not delete or rewrite past history.Updated with inverse diffCommitted cleanlyFully preserved (adds new commit)The recommended way to undo work on shared or team branches because it does not alter past commit hashes.
git reflog & recoveryEmergency Recovery NetSafeLogs every HEAD position visited. Allows recovering lost commits after accidental reset or branch deletion.Read-only inspectionUnchangedReveals all previous commit hashesReflog entries are local only and expire after 90 days by default.

Explore Git Visualizer

Git Visualizer is created by .