To unstage a specific file

git reset <file>

That will remove the file from the current index (the "about to be committed" list) without changing anything else.

To unstage all files from the current change set:

git reset

In old versions of Git, the above commands are equivalent to git reset HEAD <file> and git reset HEAD respectively, and will fail if HEAD is undefined (because you haven't yet made any commits in your repository) or ambiguous (because you created a branch called HEAD, which is a stupid thing that you shouldn't do). This was changed in Git 1.8.2, though, so in modern versions of Git you can use the commands above even prior to making your first commit:

"git reset" (without options or parameters) used to error out when you do not have any commits in your history, but it now gives you an empty index (to match non-existent commit you are not even on).

Documentation: git reset

Answer from genehack on Stack Overflow
Top answer
1 of 16
13907

To unstage a specific file

git reset <file>

That will remove the file from the current index (the "about to be committed" list) without changing anything else.

To unstage all files from the current change set:

git reset

In old versions of Git, the above commands are equivalent to git reset HEAD <file> and git reset HEAD respectively, and will fail if HEAD is undefined (because you haven't yet made any commits in your repository) or ambiguous (because you created a branch called HEAD, which is a stupid thing that you shouldn't do). This was changed in Git 1.8.2, though, so in modern versions of Git you can use the commands above even prior to making your first commit:

"git reset" (without options or parameters) used to error out when you do not have any commits in your history, but it now gives you an empty index (to match non-existent commit you are not even on).

Documentation: git reset

2 of 16
2512

You want:

git rm --cached <added_file_to_undo>

Reasoning:

When I was new to this, I first tried

git reset .

(to undo my entire initial add), only to get this (not so) helpful message:

fatal: Failed to resolve 'HEAD' as a valid ref.

It turns out that this is because the HEAD ref (branch?) doesn't exist until after the first commit. That is, you'll run into the same beginner's problem as me if your workflow, like mine, was something like:

  1. cd to my great new project directory to try out Git, the new hotness
  2. git init
  3. git add .
  4. git status

    ... lots of crap scrolls by ...

    => Damn, I didn't want to add all of that.

  5. google "undo git add"

    => find Stack Overflow - yay

  6. git reset .

    => fatal: Failed to resolve 'HEAD' as a valid ref.

It further turns out that there's a bug logged against the unhelpfulness of this in the mailing list.

And that the correct solution was right there in the Git status output (which, yes, I glossed over as 'crap)

...
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
...

And the solution indeed is to use git rm --cached FILE.

Note the warnings elsewhere here - git rm deletes your local working copy of the file, but not if you use --cached. Here's the result of git help rm:

--cached Use this option to unstage and remove paths only from the index. Working tree files, whether modified or not, will be left.

I proceed to use

git rm --cached .

to remove everything and start again. Didn't work though, because while add . is recursive, turns out rm needs -r to recurse. Sigh.

git rm -r --cached .

Okay, now I'm back to where I started. Next time I'm going to use -n to do a dry run and see what will be added:

git add -n .

I zipped up everything to a safe place before trusting git help rm about the --cached not destroying anything (and what if I misspelled it).

People also ask

What happens if I undo a `git add`, and then make additional changes?
If you undo a Git add using git reset or git restore and then make additional changes, the new changes won't be affected. The undo operation only applies to the state at the time of the undo command.
🌐
kodekloud.com
kodekloud.com › blog › how-to-undo-git-add-removing-added-files-in-git
How to Undo git add - Removing Added Files in Git
Can I undo the last `git restore` command?
No, the git restore command is not directly reversible. It's crucial to double-check the files and options before running it.
🌐
kodekloud.com
kodekloud.com › blog › how-to-undo-git-add-removing-added-files-in-git
How to Undo git add - Removing Added Files in Git
What should I do if `git reset --hard HEAD` deleted uncommitted changes?
If you've lost uncommitted changes due to a hard reset, recovery is challenging. Regularly commit or stash changes before using a hard reset to prevent accidental data loss. In extreme cases, file recovery tools may be needed.
🌐
kodekloud.com
kodekloud.com › blog › how-to-undo-git-add-removing-added-files-in-git
How to Undo git add - Removing Added Files in Git
🌐
Git
git-scm.com › book › en › v2 › Git-Basics-Undoing-Things
Git - Undoing Things
$ git commit -m 'Initial commit' $ git add forgotten_file $ git commit --amend · You end up with a single commit — the second commit replaces the results of the first. The next two sections demonstrate how to work with your staging area and working directory changes. The nice part is that the command you use to determine the state of those two areas also reminds you how to undo changes to them.
🌐
Warp
warp.dev › terminus by warp › git › undo git add
How To Undo a Git Add - For One File or All | Warp
January 31, 2024 - Warp recommended git reset which is used to reverse the effects of a git add. ... The command above is used mainly to revert changes in a workflow. The --staged option will 'restore' your files from staging back to the working directory. git ...
🌐
Git Tower
git-tower.com › learn › git faq › how to undo "git add"
How to Undo "git add" | Learn Version Control with Git
4 days ago - Luckily, there's a simple way of undoing a git add: you can simply use the git restore --staged command on the affected file:
Find elsewhere
🌐
KodeKloud
kodekloud.com › blog › how-to-undo-git-add-removing-added-files-in-git
How to Undo git add - Removing Added Files in Git
March 27, 2026 - The undo operation only applies to the state at the time of the undo command. It depends on the situation. While git reset is a powerful tool, using it to rewrite history (like resetting pushed commits) can cause issues in a collaborative environment. Communicate with your team before using reset commands that alter shared history. Git operates on a file level for standard add/reset commands, so you can't directly unstage specific lines using basic commands.
🌐
X
x.com › @freecodecamp › freecodecamp.org (@freecodecamp) on x
When you're working with Git, you might accidentally add ...
June 4, 2023 - Don't worry – there are commands to help you undo this. In this guide, @olawanle_joel explains how/ when to use git reset & git rm --cached to remove added files. https://t.co/tyujple0jl
🌐
Graphite
graphite.com › guides › how-to-undo-a-git-add
How to undo a Git add
Sometimes, you might accidentally stage files that shouldn't be committed yet. This guide will explore various methods to undo a Git add, using the git reset and git rm commands.
🌐
freeCodeCamp
freecodecamp.org › news › undo-git-add-how-to-remove-added-files-in-git
Undo Git Add – How to Remove Added Files in Git
November 7, 2024 - // stage single file git add <file> // stage multiple files git add <file1> <file2> <file3> ... When you stage files, you can confirm using the git status commands, which shows a list of all staged files: There are two major commands that you can use to undo “git add” or remove added files in Git.
🌐
Kirupa Forum
forum.kirupa.com › programming › web dev
What is your production take on How do I undo 'git add' before commit? - web dev - kirupaForum
April 2, 2026 - Pulled from common Stack Overflow threads: What is your modern answer, and where does the usual advice break down at scale? Arthur
🌐
BibSonomy
bibsonomy.org › url › 854326e3534997400dbf4f31fa9bc122
version control - How to undo 'git add' before commit? - Stack Overflow | BibSonomy
You can undo git add before commit with · git reset <file> add · git · reset · undo · unstage · Please log in to take part in the discussion (add own reviews or comments).
🌐
GitLab
docs.gitlab.com › topics › git › undo
Revert and undo changes | GitLab Docs
Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: <file> no changes added to commit (use "git add" and/or "git commit -a") ... You can undo local changes that are already staged.
🌐
GeeksforGeeks
geeksforgeeks.org › git › how-to-undo-git-add-before-commit
How to Undo 'git add' Before Commit? - GeeksforGeeks
June 27, 2024 - To undo a 'git add' before committing, you can use the 'git reset' command. This command unstages the changes that you previously added with 'git add', but it doesn't discard the changes from your working directory.
🌐
Medium
medium.com › git-happy › how-do-i-undo-git-add-before-making-a-git-commit-9d855494b269
How Do I Undo git add Before Making a Git Commit? | by Dr. Derek Austin 🥳 | git happy | Medium
May 2, 2023 - The most straightforward method to undo a git add action is to use the git restore command, which was introduced in Git version 2.23.0.
🌐
GitProtect.io
gitprotect.io › strona główna › git undo: 13 ways to undo mistakes in git
Git Undo: 13 Ways to Undo Mistakes in Git - Blog | GitProtect.io
November 24, 2025 - There exists a safe way of deleting a commit in the middle of the history: using the git revert command. It adds a new commit, which undoes everything the middle commit has changed.
🌐
CoreUI
coreui.io › answers › how-to-undo-git-add
How to undo git add · CoreUI
January 12, 2026 - Remove files from Git staging area before commit using git reset to unstage accidentally added files.
🌐
Sentry
sentry.io › sentry answers › git › undo git add before commit
Undo git add before commit | Sentry
On branch dev No commits yet Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: include.md Untracked files: (use "git add <file>..." to include in what will be committed) exclude.md
🌐
Earth Data Science
earthdatascience.org › home
Introduction to undoing things in git | Earth Data Science - Earth Lab
September 12, 2017 - Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: README.md no changes added to commit (use "git add" and/or "git commit -a") Now that you have changes that are not staged, ...
🌐
WPLauncher
blog.wplauncher.com › how-to-undo-git-add-before-commit
How to undo git add before commit? - WPLauncher
November 24, 2019 - There are two ways to undo git add prior to a commit. The first way allows you to remove all files that you added, while the second option allows you to remove one file that was added. We also include an example below to show when you would use this and what is happening. Option 1:...