Command

Git Unstage a File Command

To unstage a file in Git without discarding its working-tree edits, run git restore --staged <file>. For example, git restore --staged -- src/app.js unstages src/app.js; replace that example path with your file path.

Quick Answer

Command
git restore --staged <file>
GitCommand

Unstage a File

Type this command
git restore --staged <file>

Removes a file from the staging area but keeps your changes.

Learn More

How to unstage a file in Git

  1. Open the terminal or command interface for Git.
  2. Type git restore --staged <file>, replace any placeholders, and run it.

What unstaging changes and preserves

With --staged and no --source option, Git restores the selected path in the index (staging area) from HEAD, the current commit. It leaves the working-tree file and its edits alone. Those edits are no longer staged for the next commit; the file is not deleted from your working tree. This default requires an existing HEAD commit, so it is not the same first-commit workflow in a repository with no commits.

Unstaging is not discarding edits

git restore --staged -- src/app.js changes the index only. By contrast, git restore -- src/app.js restores the working-tree file from the index by default and can discard its unstaged edits. Without --staged, the default source is the index, not necessarily HEAD. Adding --worktree together with --staged would also change the working file; do not add it when you intend only to unstage.

Review the file before the next commit

Check the unstaged differences before deciding what to stage again. Treat the discard-file-changes task separately: it can lose edits and is not an alternative way to unstage.

Git Unstage a File Command

Run git restore --staged <file>.

Related Commands

Frequently asked questions

What is the Git command to unstage a file?

Run git restore --staged <file>.

Where do I type this Git command?

Type it in the terminal or command-line interface used by Git.

Does this Git command work on Mac and Windows?

Yes. The command text is the same on both platforms when the tool is installed.

Official source · How we verify