MicrolearnENPTES

Undo changes in a file

Lesson 6 of 24 · Git.Micro

Broke a file and want the last saved version back? git restore replaces your copy with the one Git has saved.

git restore file throws away the unstaged changes in that file.

Careful: discarded changes were never committed, so Git can't bring them back.

Restore one file at a time when other files have work you want to keep.

Check yourself

You ran git restore notes.txt by mistake. Can Git bring back the changes you had?

index.html was broken by accident. Restore it to the last commit, but keep the new paragraph you wrote in about.html.

index.html is back to its committed version

Do it in the browser: a real Git tool, a short mission and instant feedback. No install.

Start this lesson — free
← What changed? git diffTake a file out of the staging area →

All lessons · Git.Micro