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).

🌐
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 - git restore —staged README.md to undo the git add of the README.md file · git restore —staged \.md to remove all files ending in .md from the staging area
Discussions

git add - Undo git add --all - Stack Overflow
I made a mistake and called git add -all, now all files are added. I did not make a commit and push. How can I undo my action? More on stackoverflow.com
🌐 stackoverflow.com
How do I undo git add .? It seems I've added the entire main folder along with the node modules which I shouldn't have. I'm new to git
I highly – and I cannot stress this bold enough – recommend to actually read and understand all of the output git provides. Because in this picture it clearly says: No commits yet Untracked files: […] nothing added to commit but untracked files present "nothing added" means you did not do git add . (or any variant thereof), thus no need to undo it. You just initialized your repo, but nothing more. If the repo is in the wrong folder, you can just delete the .git subdirectory (rm -rf .git) and initialize it again in the correct folder. I also highly recommend to never use git add ., this will only lead to problems. Use git add for more controlled adding, or use git add -u to re-add only the modified tracked files. edit: In the future when you do need to undo an add, just read the output of git status – it will tell you the exact commands. More on reddit.com
🌐 r/git
23
0
June 8, 2024
How to Undo git add and git Commit Before Push
I always forget crap (“oh shit, that’s not what I want to publish”) so do this: Git status Shows me what files are outstanding, that I may have forgotten to commit, letting me comment then. Git log —oneline This gives me the current list of SHA1 references so I can just scroll up Git reset —hard HEAD~ You can append a number after the tilde, or just replace HEAD~ with the SHA you want to get back to. At that point; you can push just that SHA to GitHub. And then because you don’t want to lose your work, go to the correct Sha or better yet, create a new branch and fix everything (maybe even a rebase squash) and do a PR. Ah this is Reddit, no one is gonna care how messy things are locally, right? :) More on reddit.com
🌐 r/github
3
0
November 15, 2024
Git init deleted all of my work, please help
For future reference: doing git init should be the first thing you do for any project. It is never too early to start tracking changes. More on reddit.com
🌐 r/git
40
15
November 20, 2020
🌐
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.
🌐
Git Tower
git-tower.com › learn › git faq › how to undo "git add"
How to Undo "git add" | Learn Version Control with Git
5 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:
🌐
Graphite
graphite.com › guides › how-to-undo-a-git-add
How to undo a Git add - Graphite
This will unstage all files you've added. Another method to undo git add is using the git rm --cached command.
Find elsewhere
🌐
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.
🌐
Educative
educative.io › answers › how-to-undo-git-add
How to undo "git add"
We sometimes need to undo git add when files are staged by mistake (e.g., .env, node_modules, or unfinished edits). Use git reset <filename> or git reset to unstage one or all files.
🌐
devconnected
devconnected.com › home › software engineering › how to undo git add command
How To Undo Git Add Command – devconnected
December 16, 2020 - $ git restore another-file $ git ... “add” operation can also be achieved by using the “git reset” command followed by the file that you want to “unstage“....
🌐
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 - To undo the last git add while retaining changes in your working directory, use this command: ... Note: This command resets the staging area to the latest commit (HEAD) while keeping the changes in your working directory. ... Note: Replace <file> with the actual file name. This command unstages changes for the specified file. ... Note: This command unstages all changes in the staging area, leaving your working directory untouched.
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › Unstage-a-git-file-quickly
How to 'undo a git add' before you commit
Community driven content discussing all aspects of software development from DevOps to design patterns. ... The proper way to undo the git add command is to use git restore.
🌐
freeCodeCamp
freecodecamp.org › news › how-to-undo-a-git-add
How to Undo a Git Add
January 13, 2020 - To undo git add before a commit, run git reset <file> or git reset to unstage all changes.
🌐
Git
git-scm.com › book › en › v2 › Git-Basics-Undoing-Things
2.4 Git Basics - 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.
🌐
Sentry
sentry.io › sentry answers › git › undo git add before commit
Undo git add before commit | Sentry
How do I undo a git add before running git commit? To unstage files, use git reset. Without arguments, this will unstage all changes to all files. To unstage a specific file, provide its name as an argument (e.g.
🌐
Linux Handbook
linuxhandbook.com › git-undo-add
Undo Git Add and Remove Files from Staging
June 24, 2024 - The git reset is the easiest way to undo git add as it does not require any complex flags and all you have to do is append the file or path to the git reset command:
🌐
GoLinuxCloud
golinuxcloud.com › home › devops › git › git undo add (unstage files in git) with practical examples
Git Undo Add (Unstage Files in Git) with Practical Examples | GoLinuxCloud
March 16, 2026 - # Undo git add for single file git restore --staged file.txt # Undo git add for all files git reset # Remove file from staging but keep locally git rm --cached config.json # Check staged files git status # View staged changes git diff --staged
🌐
Medium
medium.com › @hackingwithcode › mistakes-happen-how-to-undo-git-add-before-committing-c5e37955e4c7
Mistakes Happen: How to Undo ‘git add’ Before Committing | by David Techwell | Medium
November 30, 2023 - Q: How can I undo a ‘git add’? A: To unstage a specific file, use ‘git reset <file>’. To unstage all changes, simply use ‘git reset’.
🌐
WPLauncher
blog.wplauncher.com › how-to-undo-git-add-before-commit
How to undo git add before commit? - WPLauncher
November 24, 2019 - Untracked files: (use "git add <file>..." to include in what will be committed) README.html · Let’s say that you would like to undo all file additions to staging prior to a commit.
🌐
YouTube
youtube.com › cameron mckenzie
Undo Git Add Before a Commit - YouTube
Need to undo Git add? Need to remove a file you added to the Git index before you commit and push to GitHub or GitLab?Don't worry. It's easy to cancel git co...
Published   October 5, 2021
Views   2K