How to undo git add
Accidentally staging files happens frequently, especially when using git add . or wildcards, and you need to remove specific files before committing.
As the creator of CoreUI with over 25 years of software development experience, I’ve unstaged countless files during development workflows.
Git provides git reset to remove files from the staging area without affecting your working directory changes.
This approach allows you to selectively unstage files while keeping your modifications intact.
Use git reset to unstage files from the staging area without losing your changes.
# Unstage a specific file
git reset path/to/file.js
# Unstage multiple files
git reset file1.js file2.js
# Unstage all files
git reset
# Alternative syntax for all files
git reset HEAD
# Unstage files in directory
git reset src/components/
# Unstage with pattern
git reset '*.log'
# Check what's staged
git status
# See what will be unstaged
git diff --staged path/to/file.js
Unstage but keep changes:
# Default behavior - keeps working directory changes
git reset path/to/file.js
# Explicitly keep changes
git reset --mixed path/to/file.js
Difference between reset modes:
# --mixed (default): unstages and keeps working directory
git reset --mixed file.js
# --soft: moves HEAD but keeps staging and working directory
git reset --soft HEAD~1
# --hard: discards staging AND working directory changes (DANGER)
git reset --hard # Don't use for unstaging!
Check current staging status:
# Show staged files
git diff --cached --name-only
# Show staged changes
git diff --cached
# Show both staged and unstaged
git status
Best Practice Note
The default git reset (equivalent to git reset --mixed) is safe—it only unstages files without touching your working directory changes. Never use git reset --hard to unstage files as it will delete your uncommitted changes. Use git restore --staged <file> as the modern alternative to git reset for unstaging (Git 2.23+). You can unstage specific hunks interactively with git reset -p. This is the daily workflow we use in CoreUI development—unstaging accidentally added debug files, configuration changes, or experimental code before creating clean commits.



