Back to lessons

Undoing Changes Safely

Learn how to undo changes at every stage of the Git workflow.

Step 1 of 714%

Git provides several ways to undo changes depending on where you are: working directory, staging area, or committed.

One of Git's strengths is that almost nothing is permanently lost — even a hard reset keeps dangling commits around for a while (visible with git reflog). The key is knowing which tool to use for each situation. Working directory changes can be discarded with restore, staged changes can be unstaged with restore --staged, and committed changes can be reverted with reset or the safer revert command.
1 / 7