How to Undo git add (Unstage Files Safely)

If you ran git add on the wrong file or staged more than you intended, you can undo it without deleting your edits. Use git restore --stagedto remove changes from Git's staging area while leaving the files in your working tree.

Practice Git workflows →

Check what you staged first

Before changing the index, check the repository status and inspect the staged diff:

git status
git diff --staged

The staging area (also called the index) is a snapshot of what the next commit will contain. Reviewing it helps you unstage only what you meant to remove.

Undo git add for one file

To unstage a single file but keep all its current edits, run:

git restore --staged -- path/to/file

Replace path/to/file with the file's path. The --separates Git options from the path, which is helpful if a filename begins with a dash. This command changes what is staged; it does not discard the file's working-tree edits.

Unstage several files or all staged changes

Pass multiple paths to unstage only those files:

git restore --staged -- src/app.js docs/guide.md

To unstage every change under the current directory, use a dot:

git restore --staged -- .

The dot means the current directory and its descendants. Run this from the repository root to unstage all staged changes, then use git status to confirm the result.

Unstage only part of a file

If a file contains both changes you want to commit and changes you want to leave out, use interactive patch mode:

git restore --staged --patch -- path/to/file

Git shows staged sections (hunks) one at a time. Review each prompt carefully, then inspect git diff and git diff --staged to confirm which changes remain unstaged and staged.

Use git reset as an alternative

Older Git tutorials often use git reset to unstage changes. For one file, the equivalent is:

git reset HEAD -- path/to/file

This updates the index to match HEAD for that path and keeps the working-tree edits. Prefer git restore --staged when available because its intent is more explicit. Avoid git reset --hard for simply undoing git add: it can discard uncommitted work.

Verify that your edits are still there

After unstaging, check both the index and your working tree:

git status
git diff --staged
git diff

The staged diff should no longer include the unstaged changes, while git diff can show edits that remain in your working tree. A newly created file may appear as untracked after it is unstaged; that is expected, and the file is still on disk.

Frequently asked questions

Does undoing git add delete my changes?

No. git restore --staged removes changes from the index but keeps them in the working tree. Do not confuse it with git restore path/to/file, which can replace working changes with the staged or committed version.

How do I unstage a file I just added?

Run git restore --staged -- path/to/file. The file becomes untracked again, but remains in your project folder. For more on unstaging, see how to unstage a file in Git.

Learn Git Faster by Practicing

Reading is just the first step. Real learning happens when you practice.

Start Learning Git →