Git commands
How git restore --staged pulls a file out of the next commit
git restore --staged: unstage, keep the edits
How to use this page
- slider / ▶Drag the slider, or press play, to watch the command happen. Before and After jump to either end.
- ← → · spaceStep through a multi-step command; space toggles Before / After.
- APlay or pause the loop (the page opens playing). Any manual input takes over.
- hoverA commit shows its message, author, date and parents, with its history highlighted.
- clickCopies the commit sha.
- ctrl + wheelZoom around the cursor (pinch on a trackpad). Double-click resets the view.
- EscStop playback, reset the view, close this menu.
- shareThe Share button copies a link to this graph, copies it as an image, downloads PNG/SVG/page, or posts it. #before, #after or #step=N in the link pins the state.
git-sim visually simulates any Git command in your own repos - from your terminal, IDE, or AI.
Table of Contents
- Introduction
- What is git restore --staged?
- Watch it happen
- Before and after
- Two restores
- Is it safe?
- How to undo it
- Try it on your repository
- Common questions
- Summary
- Next steps
- Related commands
Introduction
git restore --staged <file> is the undo for git add. You staged a file, you've changed your mind about including it in the next commit, and you want it back in the working directory as an ordinary edit. The --staged flag is doing a lot of work in that command: without it, git restore discards your edit instead.
In this article, we'll:
- Watch
git restore --staged README.mdunstage one file - Confirm the edit is still on disk
- Keep
restore --stagedand plainrestoreclearly apart
What is git restore --staged?
git restore --staged <file> copies the HEAD version of <file> into the staging area, overwriting the staged version. The working directory isn't touched, so your edit remains as an unstaged modification. It is the same operation as the older git reset HEAD <file>.
Watch it happen
Our sample repo has one file staged by mistake. Here's git restore --staged README.md:
- Before:
README.mdis staged, its edit added to the index. - Git resets
README.mdin the index to its version inHEAD, so the edit is unstaged again. - The branch and every commit stay put, and the file on disk still has your edit. Unstaging never moves
HEAD.
Before and after
git status --short before:
M README.md
and after:
M README.md
One column over. The commit graph is unchanged:
The raw git output, if you want to read along in text
git log --oneline --graph --all
before
* 1117a34 (feature) Add search tests
* e5869f0 Fix typo in search box
* fc19889 Add search box
| * 8c02d5b (HEAD -> main) Update dependencies
| * a0b2db3 Add user settings page
|/
* 96c4fc2 Fix header layout
* ae65976 Add login page
* 3e1ffe4 Add project skeleton
* 4114b2c Initial commitafter
* 1117a34 (feature) Add search tests
* e5869f0 Fix typo in search box
* fc19889 Add search box
| * 8c02d5b (HEAD -> main) Update dependencies
| * a0b2db3 Add user settings page
|/
* 96c4fc2 Fix header layout
* ae65976 Add login page
* 3e1ffe4 Add project skeleton
* 4114b2c Initial commitTwo restores
The flag decides which direction the copy goes (the git restore documentation covers --worktree too):
git restore --staged <file>copies fromHEADinto the staging area. Your working copy is untouched. Harmless.git restore <file>copies from the staging area into the working directory. Your edit is overwritten. Not recoverable.
Both are "restore", and the second one is on its own page because it deserves a warning of its own. Here it is on the same repo, so the two sit side by side:
unstage would have been a fine verb. As it is, I've trained myself to type --staged first and the file name second, so the dangerous form is never a partial version of what I meant to type.
Is it safe?
Safe git-sim pre-flight
Unstages changes; working tree files keep their content.
The staged version is replaced by the committed one, and your working copy keeps the edit. Nothing is lost.
How to undo it
git add README.md
Try it on your repository
pip install git-sim
git-sim restore --staged README.md
git-sim shows the file moving out of the staging area with the working directory unchanged.
Common questions
What does git restore --staged do?
It unstages the named files, copying the HEAD version into the staging area while leaving your working copy alone.
What is the difference between git restore and git restore --staged?
--staged unstages and keeps your edit. Without it, restore overwrites your working copy and discards the edit.
Is git restore --staged the same as git reset HEAD file?
Yes. restore --staged is the newer spelling, added in Git 2.23.
How do I unstage everything?
git restore --staged .
Summary
In this article, we watched git restore --staged move a file out of the staging area while the edit stayed on disk, and drew the line between it and plain git restore, which discards edits.
Next steps
git restore covers the other direction. git add is the command this undoes.
Related commands
- git reset HEAD file, the older spelling
- git add, the operation being undone
- git restore, the discarding form
- git status, to see what's staged
- git commit, what the staging area feeds
- git stash, to set the edit aside entirely
