How do Git restore options differ for staged and unstaged changes?
Quick answer
git restore --staged <path> removes that path’s staged difference from the index by restoring it from HEAD; it leaves working-tree edits in place. git restore <path> restores the working-tree file from the index, so it can discard unstaged edits. Using both --staged and --worktree changes both locations. Check status and the relevant diffs before choosing.
The question, the details, the next step.
A practical checklist
Run
git status --shortand identify the exact path you plan to affect.Review
git diff --cached -- <path>for staged changes.Review
git diff -- <path>for unstaged working-tree changes.Choose whether to change the index, working tree, or both.
Read the command and path carefully; inspect status and diffs afterward.
A few more useful answers
Does `git restore --staged <path>` erase my unstaged edits too?
Can `git restore <path>` discard changes I have not staged?
Does checking a diff guarantee I can recover changes after restoring?
No. The diffs help you identify staged and unstaged changes before acting, but they do not guarantee recovery of discarded edits. [S2]
Sources
References used for this guide.
- [S1] Git - git-restore Documentation git-scm.com · Checked
- [S2] Git - git-diff Documentation git-scm.com · Checked
