Undoing Safely
The three undos, in increasing order of danger.
git restore --staged file unstages a file, leaving your edits alone. Completely safe.
git restore file throws away uncommitted changes to that file. Destructive, and there is no undo, because those changes were never recorded.
git revert creates a new commit that reverses an old one, leaving history intact. Safe, and the right tool when a change is already shared.
✦ Anything committed can be recovered. Anything not committed cannot.
This is the single most useful thing to understand about git. Once you commit, that state exists forever and almost any mistake is recoverable. Before you commit, your work exists only on disk and a careless restore erases it permanently. That asymmetry is a good argument for committing often, even for work in progress.
Mark this lesson complete
Signed in, your progress follows you to every device.