Git Undo git add Operation Guide
When to Use
You've already run git add but haven't run git commit yet, and now you want to remove files from the staging area while keeping the modifications in your working directory.
Check Current State First
git status --short
git diff --cached --name-only
git status --short-- confirm which files are already in the staging area.git diff --cached --name-only-- list only files that are staged and ready for the next commit.
Recommended Commands
| Scenario | Recommended Command | Result |
|---|---|---|
| Unstage a single file | git restore --staged <file> | File removed from staging, working directory changes preserved |
| Unstage multiple files | git restore --staged file1 file2 | Multiple files removed from staging at once |
| Unstage everything in current directory | git restore --staged . | Batch unstage |
Common Scenarios
Unstage a Single File
git restore --staged mock.png
Unstage Multiple Files
git restore --staged README.md src/app.js
Unstage All Staged Content
git restore --staged .
If a file was originally new, unstaging it returns it to "untracked" status rather than being deleted.
Legacy Syntax
The old syntax was typically:
git reset HEAD <file>
git reset HEAD
These still work, but git restore --staged is now preferred because its semantics are more direct and easier to read.
Risks and Boundaries
- These commands only affect the staging area -- they won't delete your working directory changes.
- If you want to discard working directory changes too, use
git restore <file>instead of just--staged. - If the file has already been committed, undoing
git addwon't affect commit history.
Related Commands
git diff --cached # View staged but uncommitted changes
git restore <file> # Discard tracked changes in working directory
git restore --source=HEAD --staged --worktree <file> # Unstage and discard working directory changes at once