pull/this/repo

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.

RoundupHow to unstage a file in Git (git restore --staged vs 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:

terminal
git restore --staged app.js

Check 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:

terminal
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:

terminal
git reset app.js

The 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.

CommandResult for a fileWorks on
git restore --staged <file>unstaged, edits keptGit 2.23 and later
git reset <file>unstaged, edits keptevery Git version
git reset HEAD <file>the same as aboveevery Git version
git rm --cached <file>removed from the index, file kept on diskevery 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:

terminal
# everything staged under the current folder
git restore --staged .

# everything staged in the repo
git reset

Plain 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:

terminal
git rm --cached newfile.txt

The 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:

CommandStaging areaYour file on disk
git restore --staged app.jsreset to last commituntouched
git restore app.jsuntouchedreset to the staged copy, edits lost
git restore --staged --worktree app.jsreset to last commitreset to last commit, edits lost
git reset --hardreset for every fileevery 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:

terminal
git restore --staged -p app.js

Git 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

  1. 1git-scm.com: git restore (read 2026-11-22)
  2. 2git-scm.com: git reset (read 2026-11-22)
  3. 3git-scm.com: git rm (read 2026-11-22)
  4. 4git-scm.com: git stash (read 2026-11-22)
  5. 5Git 2.23.0 release notes (read 2026-11-22)

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.