Undo & History

How to Unstage Files from Git (Undo git add)

Remove files from the Git staging area (index) without losing any of your local changes.

Instant 1-Line Solution
Safe CommandBeginner
git restore --staged <file>
When to use this scenario:You accidentally ran "git add ." and included sensitive files (like .env or large build binaries) you didn't intend to commit.

Step-by-Step Execution Guide

1Unstage a single specific file
git restore --staged <file-path>

Removes the file from index; your changes remain safe in your working directory.

2Unstage all staged files at once
git restore --staged .

Clears the entire staging area back to unstaged modified state.

Critical Pitfalls & Precautions

  • β€’Do NOT confuse "git restore --staged <file>" with "git restore <file>". Omitting "--staged" will permanently wipe your changes!
Frequently Asked Questions

Unstage Files (Undo git add) - Frequently Asked Questions

Common questions about safe rollback, remote history implications, and troubleshooting.

Older Git versions used "git reset HEAD <file>". Both achieve the same result, but "git restore --staged" is the clearer modern syntax.