How to unstage a file in Git (git restore --staged vs git reset)
By Pull This RepoPosted 4 min read
Short answer
To unstage a file in Git, run git restore --staged followed by the file name. It takes the file out of the next commit and keeps your edits. On Git older than 2.23, run git reset with the file name, which does the same thing. To unstage everything, run git restore --staged with a dot, or plain git reset.
To git unstage a file, run git restore --staged with its name. The file drops out of the next commit, and every edit you made stays in the file. On older Git, git reset with the file name does the same job. This page shows both, how to unstage everything at once, how to undo git add in a brand new repo, and the one command that does throw your changes away. All commands were checked against the Git docs on git-scm.com on 22 November 2026.
How do you unstage a file in Git?
Run this, with your file's path:
git restore --staged app.jsCheck the result with git status. The file moves from "Changes to be committed" back to "Changes not staged for commit". The git restore docs say --staged restores only the index, the staging area, and that it restores from HEAD, your last commit, by default. Nothing in your working folder changes.
You can name several files, a folder, or a quoted pattern:
git restore --staged app.js styles.css
git restore --staged src/
git restore --staged '*.log'How do you undo git add with git reset?
Give git reset a file name:
git reset app.jsThe git reset docs describe this form as "the opposite of git add": it unstages all changes to the named files and is "equivalent to git restore --staged". Many guides show git reset HEAD app.js. That is the same command; HEAD is the default when you leave it out.
| Command | Result for a file | Works on |
|---|---|---|
git restore --staged <file> | unstaged, edits kept | Git 2.23 and later |
git reset <file> | unstaged, edits kept | every Git version |
git reset HEAD <file> | the same as above | every Git version |
git rm --cached <file> | removed from the index, file kept on disk | every Git version |
Why does git restore --staged exist if git reset already works?
Because git reset does several unrelated jobs. With a commit and no file it moves your branch, and with --hard it overwrites files. The Git 2.23.0 release notes say git switch and git restore were added to split jobs out of git checkout, and git restore gives "put this file back" one clear name. If your Git is older than 2.23, git restore will not exist; check with git --version.
How do you unstage all files?
Use a dot for the current folder, or plain git reset:
# everything staged under the current folder
git restore --staged .
# everything staged in the repo
git resetPlain git reset uses its default --mixed mode with HEAD, which the docs say leaves your working directory unchanged and updates the index "so nothing will be staged". It does not move your branch, because you are resetting to the commit you are already on.
How do you unstage a new file that was never committed?
git restore --staged newfile.txt works when the repo has at least one commit; the file goes back to untracked. In a repo with no commits yet there is no HEAD to restore from, and Git stops with fatal: could not resolve HEAD. Use git rm --cached instead:
git rm --cached newfile.txtThe git rm docs say --cached will "unstage and remove paths only from the index" and that working tree files "will be left alone". For a folder, add -r: git rm -r --cached build/.
Be careful with git rm --cached on a file that is already committed. It stages the file's removal, so your next commit deletes it from the repo, even though the copy on your disk stays.
What is the difference between unstaging and discarding changes?
Unstaging changes only what goes into the next commit. Discarding changes rewrites the file on disk. They look similar, so check the flags:
| Command | Staging area | Your file on disk |
|---|---|---|
git restore --staged app.js | reset to last commit | untouched |
git restore app.js | untouched | reset to the staged copy, edits lost |
git restore --staged --worktree app.js | reset to last commit | reset to last commit, edits lost |
git reset --hard | reset for every file | every tracked file reset, edits lost |
The git restore docs say that without --staged or --worktree it restores the working tree, and with both it restores both. If you want your edits out of the way without losing them, stash them instead; the git stash guide covers that.
How do you unstage only part of a file?
Add --patch, or -p:
git restore --staged -p app.jsGit shows each staged hunk and asks whether to unstage it. git reset -p app.js does the same on any version. This pairs well with git add -p, which stages only the parts you choose.
What is the catch?
None of these commands touch commits. If you already ran git commit, the file is in the history, and unstaging will not remove it. To take a file out of the last commit you need git reset --soft HEAD~1 or git commit --amend, both listed in our Git cheat sheet. If you meant to grab a file from somewhere else rather than undo your own change, see how to get a file from another branch in Git.
Pull it. Stash it.
Questions people ask
How do I undo git add?
Run git restore --staged followed by the file you added, or git reset followed by the file. Both put the staged copy back to the last commit's version, so the file is no longer part of the next commit. Your changes stay in the file on disk.
Does unstaging a file delete my changes?
No. git restore --staged and git reset with a file name only change the staging area. The edits in your working folder are left alone. Changes are only thrown away if you also restore the working tree, for example with git restore and no --staged flag, or with git reset --hard.
What is the difference between git restore --staged and git reset?
For a single file there is no difference in result. The git reset docs say git reset with a path is equivalent to git restore --staged with that path. git restore arrived in Git 2.23 as a clearer command for restoring files, while git reset also moves branches when you give it a commit.
How do I unstage a file in a repo with no commits yet?
Use git rm --cached followed by the file name. The git rm docs say --cached unstages and removes paths only from the index and leaves the working tree files alone. In a brand new repo there is no previous commit for git restore --staged to restore from.
Sources
More repos like this
Get tomorrow's repo in your feed
One free, open source repo a day as a short video, shown working, with the catch named. Pull it. Stash it.
