Git Restore
Restore
Section titled “Restore”Purpose
Section titled “Purpose”Discard working tree changes or unstage files using the modern restore command.
Commands
Section titled “Commands”git restore <file>
- Discard unstaged changes in a file
- Use when you want to revert a file to the last committed state
- Example:
git restore README.md
git restore --staged <file>
- Unstage a file while keeping its local edits
- Use when the file should not be part of the next commit
git restore --source=<commit> <file>
- Restore a file from a specific commit
- Use when recovering an earlier file version without resetting the whole branch
git restorechanges the working tree, so checkgit statusfirst- Restoring a file overwrites local changes in that file