Git Cheat Sheet · Changes
Unstage
git restore --staged <file>
To remove a file from the index without touching its content, run git restore --staged <file>. Your changes are kept: they simply go back to "unstaged" and will not go into the next commit.
What it does
Removes changes from the index without losing them: they become "unstaged" again.
A use case
You staged a local configuration file by mistake.
On the command line
git restore --staged <file>- Unstages a file (Git 2.23 and later).
git restore --staged .- Empties the whole index.
git reset <file>- Older syntax, equivalent.
git restore --staged -p <file>- Unstages only some blocks.
In Merathon
- Hover the file in "Staged" and click the minus button ("Unstage"), or right-click → "Unstage".
- "Unstage all" empties the index; from the diff, "Unstage hunk" or "Unstage lines".
Frequently asked questions
Does git restore --staged delete my changes?
No. Only git restore <file>, without --staged, discards the changes in the working copy.
How do I remove from the index a file that should be ignored?
git rm --cached <file> stops tracking it without deleting it from disk. Then add it to .gitignore.