Skip to content
Guest
Learn Git · Course Syllabus Show lessons
Safety & Recovery · 8 min read · Beginner

Undoing Changes, Stash & Revert

Fix mistakes confidently with git restore, git stash, git reset, and git revert without losing work.

What you'll learn

  • Temporarily shelve unfinished edits with git stash and git stash pop
  • Discard unstaged edits safely with git restore
  • Choose git revert over git reset on shared branches

Every developer makes mistakes in Git. Knowing which undo command matches your situation prevents panic and data loss.

Choosing the Right Undo Tool

SituationRecommended CommandSafe on Shared Branch?
Need to switch branches mid-editgit stash / git stash popYes
Discard unstaged edits in a filegit restore file.jsYes
Undo a commit already pushed to maingit revert <hash>Yes (adds an inverse commit)
Move a local unpushed commit back to staginggit reset --soft HEAD~1Local only

Fill-in-the-Blank Exercise

Safe Recovery Commands

Temporarily save uncommitted work, and later safely undo a pushed commit on main.

git 
git  a1b2c3d

Try It Yourself (Interactive Git Terminal)

GitInspect History Before Undoing
main
(main) $ git status
On branch main
Untracked files: index.html, styles.css

Check Your Understanding

Score: 0 / 1

1. Which command safely undoes a buggy commit that has already been pushed to main?

Study Workspace

Finished this lesson?

Your progress is saved locally in your browser, no account needed.

Search courses, lessons, and references

Type to search across all courses, lessons, and quick references.

Press Esc to close Powered by Pagefind