git restore becomes easier to remember when you ask two questions: where is the content coming from, and where is it going?
| |
The first command discards unstaged edits to that tracked file. It does not necessarily restore the last commit: its default source is the index, which may contain staged changes.
With --staged, the default source is HEAD. That makes the second command useful for unstaging without throwing away the edited file.
Before restoring working-tree content, inspect git diff -- path/to/file; inspect staged content with git diff --cached -- path/to/file. Uncommitted content overwritten by restore may not be recoverable through Git.
The -- separates options from file paths. It makes the intended target explicit and avoids ambiguity when a path resembles an option.
Reference: git-restore documentation.