git restore

git restore reverts file changes in a Git repository. Use it deliberately: restoring a file can discard work that has not been committed.

What you will learn

Common commands

# Discard unstaged changes in one file
git restore index.html

# Unstage a file but keep its edits
git restore --staged index.html

# Restore from a specific commit
git restore --source=HEAD~1 -- report.txt

The default target is the working tree. With --staged, Git changes the index instead and leaves the working-tree edits in place.

Common mistakes