git restore --staged: Unstage Files & CI Errors
git restore --staged is the clear, modern way to unstage files while keeping your edits.
When you over-stage, restore --staged removes files from the index without discarding your working-tree changes.
What it does
git restore --staged copies content from HEAD into the index for the named paths, effectively unstaging them, while leaving the working-tree files exactly as they are.
Common usage
Terminal
git restore --staged file.txt # unstage one file
git restore --staged . # unstage everything
# equivalent older form:
git reset HEAD file.txt
# unstage AND discard:
git restore --staged --worktree file.txtCommon errors in CI
error: pathspec did not match - the path is not staged or is mistyped. Remember --staged alone keeps your edits (only unstages); to also throw the edits away you must add --worktree. On a brand-new repo with no HEAD, unstaging needs git rm --cached instead.
Related guides
git restore: Usage, Options & Common CI Errorsgit restore discards working-tree changes or unstages files. Reference for --staged, --source, --worktree, an…
git reset: Usage, Options & Common CI Errorsgit reset moves HEAD and optionally the index and working tree. Reference for --soft, --mixed, --hard, and ho…
git add: Usage, Options & Common CI Errorsgit add stages changes for the next commit. Reference for -A, -p, --update, and the pathspec and ignored-file…
git status: Usage, Options & Common CI Errorsgit status shows staged, unstaged, and untracked changes plus branch state. Reference for -s, --porcelain, -b…