All How-Tos
Beginner

How to Unstage Files Without Losing Changes in Git

Learn how to unstage files while keeping your changes in the working tree.

Unstage One File

To undo git add for a file, restore its entry in the Index (staging area) to the last commit. The file in your working tree keeps all of your local edits.

git restore --staged -- <file>

Unstage All Files

From the repository root, use the following command to unstage all changes. Your working files remain unchanged.

git restore --staged -- .

Unstage Selected Changes

If only part of a file should be removed from the Index, use patch mode. Git shows one chunk of changes at a time: answer y to unstage it or n to keep it staged.

git restore --staged --patch -- <file>

Check What Is Still Staged

Review the changes that will be included in your next commit. An empty diff means that nothing is staged.

git diff --cached

Considerations

  • Keep the --staged option: omitting it restores the working file and can discard local edits.
  • Unstaging a newly added file makes it untracked again. Unstaging a deletion leaves the file deleted in your working tree; it only removes the deletion from the next commit.
  • These commands require an existing commit. Before your first commit, use git reset -- <file> to unstage a newly added file while keeping it locally.
  • To undo a commit you already created, see Undo Last Commits.