Git Undo Add: Unstage Files After git add

Tested on RHEL 10.2 (Coughlan)
Package git 2.52.0
Applies to Any host with Git installed
Privilege Normal user
Scope Undo git add before commit — the mistake of staging too much or the wrong file. Covers git restore --staged, git reset HEAD, and staged deletions. For broader unstage workflows (git rm --cached, folders, command comparison), see Git unstage files — not a discard or reset tutorial.
Related guides Git unstage files
Git discard changes
Git restore examples
Git reset examples
Remove file from tracking

Undoing git add means reversing a staging mistake — you staged a path you did not mean to include in the next commit. Your edits stay on disk; Git resets the index entry for that path toward HEAD. If you need a full guide to every unstage command (git rm --cached, folders, and comparisons), see Git unstage files.

Four situations this article covers:

  • read git status -sb to see what is staged;
  • unstage one file you added by mistake;
  • undo git add . for every staged path;
  • unstage a deletion you staged with git add or git rm.

Pick your status line in the table below, then jump to that section. These commands apply only before git commit; committed work needs Git reset examples or revert to previous commit.


Choose the Right Unstage Command

git status -sb What you want Command
M file Unstage one file, keep edits on disk git restore --staged file
M file1 and M file2 Unstage several paths git restore --staged file1 file2
Many M paths in column 1 Undo git add . git restore --staged . from repo root, or bare git reset for the whole repo
D file Unstage a staged deletion git restore --staged file
MM file Unstage only; keep working-tree edits git restore --staged file
MM file Drop staged and unstaged edits git restore --staged --worktree file — see Git discard changes
Stop tracking, keep file on disk Not undo add git rm --cached file — see remove file from tracking

No commits yet? git restore --staged needs HEAD. In a newly initialized repository before the first commit, use git reset <path> instead.

These unstage commands do not delete untracked files from disk.


Read git status -sb First

Scenario: you ran git add and want to confirm what is staged before you unstage.

Short status shows the branch on the first line, then one row per changed path. Read the two change columns from left to right:

bash
git status -sb
output
## main
M  app.txt
 M notes.txt

The first column is the staging area; the second is the working tree. In the sample output, M app.txt has M in the first column, so that change is staged. M notes.txt has M in the second column only, so the file is modified in the working tree but not staged.


Unstage One File

Scenario: you staged app.txt but meant to leave it out of the next commit.

With app.txt staged and notes.txt only modified on disk, status looks like the block above. Remove app.txt from the staging area:

bash
git restore --staged app.txt

Check that only the working-tree column still shows app.txt:

bash
git status -sb
output
## main
 M app.txt
 M notes.txt

Both files still have your edits — app.txt is simply unstaged again. Nothing was deleted from disk.

In a brand-new repository with no commit yet, git restore --staged may fail with fatal: could not resolve HEAD because it restores the index from HEAD. Use git reset file instead — see Troubleshooting.


Undo git add .

Scenario: you ran git add . and want every path out of the staging area at once.

Assume both files were staged:

bash
git status -sb
output
## main
M  app.txt
M  notes.txt

Unstage paths under the current directory — . means this directory and everything below it. Run it from the repository root if you intend to unstage changes across the whole repo:

bash
git restore --staged .

Confirm both files show a space in the first column:

bash
git status -sb
output
## main
 M app.txt
 M notes.txt

Bare git reset also unstages changes while keeping working-tree edits, but it applies to the repository's staged changes rather than being limited by the . pathspec. When the goal is specifically to undo git add ., run git restore --staged . from the repository root.


Unstage With git reset HEAD

Scenario: you follow a script or tutorial that uses git reset HEAD to undo git add.

After staging app.txt:

bash
git reset HEAD app.txt
output
Unstaged changes after reset:
M	app.txt
M	notes.txt

Short status confirms app.txt is unstaged:

bash
git status -sb
output
## main
 M app.txt
 M notes.txt

This is the traditional alternative to git restore --staged. On modern Git, both achieve the same unstage result for a single file — see Git restore examples for restore-focused workflows.


Unstage a Staged Deletion

Scenario: you deleted a tracked file and staged that removal, but you want the delete out of the index before commit.

After rm tracked.txt and git add tracked.txt, status shows a staged deletion:

bash
git status -sb
output
## main
 M app.txt
 M notes.txt
D  tracked.txt

D in the first column means the deletion is staged. Unstage it:

bash
git restore --staged tracked.txt

The deletion moves out of the staging area — the file is still missing on disk until you restore it:

bash
git status -sb
output
## main
 M app.txt
 M notes.txt
 D tracked.txt

D tracked.txt means unstaged deletion. To bring the file back from the last commit, run git restore tracked.txt — that is a separate step from undoing git add.


git rm --cached Is Not Undo Add

Unstaging reverses git add when you still want the file tracked. If you only staged a file by mistake, use git restore --staged file. Use git rm --cached when the goal is to stop tracking the path while keeping it on disk — see remove file from tracking and gitignore examples.


After git commit

Once you run git commit, the snapshot is in history. After the commit is created, those changes are no longer in the staging-area state you are trying to undo — you now need to undo or change the commit instead. Use Git reset examples or revert to previous commit.


Troubleshooting

Symptom Likely cause Fix
git restore --staged file says could not resolve HEAD Repository has no commits yet Use git reset file to unstage the newly added path
git restore --staged seems to do nothing Path was not staged, or typo in filename Run git status -sb; match the path exactly
git reset did not unstage Changes were already committed Use reset or revert on the commit, not unstage commands
File still shows M after unstage Expected — unstage only clears column 1 Edits remain in column 2 until you commit or discard
Wanted to delete staged changes entirely Unstage alone keeps disk content git restore --staged --worktree file discards both staged and unstaged changes for that file — see Git discard changes
Confused git rm --cached with undo add Different goal — stop tracking Remove file from tracking
Staged delete still gone after unstage Unstage only removed index deletion git restore tracked.txt to recover file content from HEAD

References


Summary

Undoing git add removes paths from the staging area and leaves your edits on disk. git status -sb shows what is staged — look for M or D in the first column. Use git restore --staged file for one path, or git restore --staged . from the repo root to reverse git add ..

Before the first commit, use git reset file if git restore --staged cannot resolve HEAD. Bare git reset unstages the whole repository; git reset HEAD file is also valid on repos with history. Staged deletions use the same unstage command — then git restore file if you need the file back from HEAD.

This page targets undo git add mistakes before commit. For broader unstage command coverage — git rm --cached, directories, and side-by-side comparisons — see Git unstage files. To discard edits or undo commits, see Git discard changes and Git reset examples.


Frequently Asked Questions

1. How do I undo git add in Git?

Run git restore --staged file. Git resets that path in the staging area to match HEAD, while your working-tree edits stay on disk.

2. How do I undo git add . for all files?

Run git restore --staged . from the repository root to unstage paths under the current directory. Bare git reset unstages all staged paths in the repo. Both keep your file edits on disk.

3. What is the difference between git restore --staged and git reset HEAD?

For unstaging, both can produce the same result. git restore --staged is the more purpose-specific command, while git reset HEAD file is also valid and widely used.

4. Does undoing git add delete my changes?

No. Unstaging resets the index entry toward HEAD. The file content you edited in your working tree remains until you discard it or commit it.

5. How do I remove a staged file but keep it locally?

If you only staged the file by mistake, use git restore --staged file. Use git rm --cached file when the goal is to stop tracking the file while keeping it on disk.

6. Can I undo git add after git commit?

No. After the commit is created, those changes are no longer in the staging-area state you are trying to undo. Undo or change the commit with git reset or git revert instead.
Deepak Prasad

R&D Engineer

Founder of GoLinuxCloud with more than 15 years of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive experience, he excels across development, DevOps, networking, and security, delivering robust and efficient solutions for diverse projects.

  • Go (programming language)
  • Python (programming language)
  • DevOps
  • Computer Security
  • Cloud Computing
  • Kubernetes
  • Linux
  • Ansible (software)