/commands/git/unstage-file-git-restore-staged
Unstage a file in Git: git restore --staged FILE
verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · git version 2.55.0.windows.5updated
- tool
- Git
- versions
- Git 2.23+ (git restore), git reset HEAD: all versions
- os
- any
git restore --staged FILE undoes git add FILE: it removes the file's changes from the staging area (the index) so they are not part of the next commit. Your edits stay in the working tree, untouched. Use git restore --staged . to unstage everything. Before Git 2.23 the same command was git reset HEAD FILE (or git reset FILE), which still works.
Example
git init -q repo && cd repo
printf 'v1\n' > app.txt && git add app.txt && git commit -q -m "initial"
printf 'v2\n' > app.txt
printf 'draft\n' > notes.txt
git add .
echo "--- staged"
git status --short
git restore --staged notes.txt app.txt
echo "--- after git restore --staged"
git status --short
echo "--- working tree is unchanged"
cat app.txt notes.txtOutput
--- staged M app.txt A notes.txt --- after git restore --staged M app.txt ?? notes.txt --- working tree is unchanged v2 draft
In git status --short the first column is the staging area and the second the working tree: M and A are staged changes, M is a modified file that is not staged, and ?? is an untracked file.
Variants
| Goal | Command |
|---|---|
| Unstage one file, keep the edits | git restore --staged FILE |
| Unstage everything | git restore --staged . |
| Unstage only some hunks | git restore --staged -p FILE |
| Same thing, older Git | git reset HEAD FILE (or git reset FILE) |
| Repository with no commits yet | git rm --cached FILE (there is no HEAD to restore from) |
| Unstage AND discard the edits | git restore --staged --worktree FILE |
To stop tracking a file that is already committed (for example after adding it to .gitignore), unstaging is not enough: use git rm --cached.
Sources
Related pages
commands · gitStop tracking a file but keep it locally: git rm --cachedgit rm --cached FILE removes a file from the repository index but leaves it on disk. Add it to .gitignore and commit. Why .gitignore alone does not untrack it.commands · gitgit reset --soft HEAD~1: undo the last commit, keep the changesUndo the last commit and keep its changes staged with git reset --soft HEAD~1. --mixed unstages them, --hard deletes them. Undo a reset with the reflog.compare · gitgit switch vs git checkout: which one to usegit switch changes branches and git restore restores files; git checkout does both. Why the Git 2.23 commands are safer, with equivalents side by side.