Skip to content

/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

bash
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.txt

Output

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

GoalCommand
Unstage one file, keep the editsgit restore --staged FILE
Unstage everythinggit restore --staged .
Unstage only some hunksgit restore --staged -p FILE
Same thing, older Gitgit reset HEAD FILE (or git reset FILE)
Repository with no commits yetgit rm --cached FILE (there is no HEAD to restore from)
Unstage AND discard the editsgit 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