Unstaging a File
Git restore --staged.
Sometimes you git add a file by accident. You don't want to lose your edits. You just want to take the file out of the staging box.

- You staged something by accident
- Keep the edits
- Just take it out of the box
Taking it back out
We changed two files, and added both with git add dot. But the style change isn't ready yet. Status shows both are staged. Now git restore, dash dash staged, and the style file. Status again. The page is still staged, but the style file is back to modified, and not staged. And our edit is still there in the file.
git add . git status --short M index.html M style.css git restore --staged style.css git status --short M index.html M style.css cat style.css body { font-family: sans-serif; } p { color: gray; }
Two kinds of restore
So there are two restores. With dash dash staged, it takes the file out of staging, and keeps your edits. Without it, it throws your edits away. Git status even reminds you of both commands, every time you run it.
git restore --staged
- Unstages the file
- Your edits stay
git restore
- Discards the edits
- Back to last commit
Summary
git restore dash dash staged unstages a file but keeps your work. Next, fixing a commit you just made.
Key takeaways- git restore --staged <file>
- Edits are kept
- Status shows the hints