git reset -- FILE_NAME will do it.

See the git reset manual:

This means that git reset <pathspec> is the opposite of git add <pathspec>

Answer from Christoffer Hammarström on Stack Overflow
Discussions

How do I undo the last commit without losing changes?
just committed but realized I need to edit some files before finalizing. How can I undo the last commit but keep my changes in the files? More on github.com
🌐 github.com
3
2
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
New to git, advice needed. Revert commit but keep changes
You can either reset, as u/large_crimson_canine suggested, or you can make your new changes, git add them and then amend the commit you already made with: git --amend or, to retain the previous commit message: git --amend --no-edit More on reddit.com
🌐 r/git
17
0
November 18, 2023
People also ask

How to Undo "git add"
To undo git add and remove a file from the staging area without discarding any of your actual edits, run git restore --staged (Git 2.23+) or the older equivalent git reset HEAD . This moves the file back to the 'modified but not staged' state, so your changes in the working directory are fully preserved. To unstage everything in one go, run git restore --staged . or git reset HEAD. This operation is completely safe and reversible — no data is lost, and you can re-stage the file at any time with git add. Use git diff --cached before committing to review exactly what is staged, so you catch acc
🌐
git-tower.com
git-tower.com › learn › git faq › how to undo "git add"
How to Undo "git add" | Learn Version Control with Git
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
🌐
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 - These are the git reset and git rm --cached commands. But these commands are quite different from each other. git reset is used to unstage changes that have been added to the staging area.
🌐
Git Tower
git-tower.com › learn › git faq › how to undo "git add"
How to Undo "git add" | Learn Version Control with Git
6 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: ... This will remove the file from Git's staging area, making sure it is NOT part of the next commit.
🌐
Graphite
graphite.com › guides › how-to-undo-a-git-add
How to undo a Git add
Another method to undo git add is using the git rm --cached command. This is particularly useful when you want to completely remove files from the staging area but keep them in your working directory, especially useful for files that were newly ...
🌐
Git
git-scm.com › book › en › v2 › Git-Basics-Undoing-Things
Git - Undoing Things
$ git restore --staged CONTRIBUTING.md $ git status On branch master Changes to be committed: (use "git restore --staged <file>..." to unstage) renamed: README.md -> README Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: CONTRIBUTING.md · The CONTRIBUTING.md file is modified but once again unstaged. What if you realize that you don’t want to keep your changes to the CONTRIBUTING.md 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 - 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.
🌐
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 - 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 restore —staged README.md to undo the git add of the README.md file
🌐
Aviator
aviator.co › home › blog › how to git undo commit: methods and best practices
How to Git Undo Commit: Methods and Best Practices - Aviator Blog
February 10, 2025 - These tools allow you to fix issues without permanently losing work. To unstage a file after git add, use git reset HEAD <file-name>. This moves the file back to the working directory but keeps the changes.
🌐
CoreUI
coreui.io › answers › how-to-undo-git-add
How to undo git add · CoreUI
January 12, 2026 - # Default behavior - keeps working directory changes git reset path/to/file.js # Explicitly keep changes git reset --mixed path/to/file.js ... # --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!
🌐
Medium
medium.com › codex › undo-your-breakfast-meet-git-8-433a1c6cb1e1
How to undo changes in Git? | CodeX
December 29, 2022 - Of course, Git includes a safety button called git reflog that allows you to restore commits even after using git reset --hard, but that is definitely a topic for another article.
🌐
Initial Commit
initialcommit.com › blog › undoing-changes-in-git
A Comprehensive Guide to Undoing Changes In Git
April 18, 2022 - For example, if you edited a file to add 10 lines of code, then when you use git revert, these 10 lines of code will be removed. You will still be able to see that you added and then removed these 10 lines.
🌐
JetBrains
jetbrains.com › help › idea › undo-changes.html
Undo changes in Git repository | IntelliJ IDEA Documentation
May 5, 2026 - Keep: committed changes made after the selected commit will be discarded, but local changes will be kept intact. If you need to revert a single file instead of discarding a whole commit that includes changes to several files, you can return ...
🌐
Educative
educative.io › answers › how-to-undo-git-add
How to undo "git add"
Use git reset <filename> or git reset to unstage one or all files. Use git restore --staged <filename> or git restore --staged . as a newer, safer alternative. Both commands remove files from the staging area but keep your changes ...
🌐
Nobledesktop
blog.nobledesktop.com › learn › git › undo changes in git: git checkout, git revert, & git reset
Undo Changes in Git: checkout, revert, & reset
April 19, 2026 - For example, to undo the last 2 commits (assuming both have not been pushed) run Git reset—soft HEAD~2 · NOTE: Git reset—soft HEAD~ is the same as Git reset—soft HEAD^ which you may see in Git documentation.
🌐
Graphite
graphite.com › guides › remove-files-from-git-add
How to remove files after running git add
However, if changes are added to the index mistakenly, Git provides ways to revert this operation before a commit is made.
Top answer
1 of 6
127

Update (couple of years later)

Jan Hudec

It's trivial to remove it from index only.

True: you can reset a file to its index content easily enough, as the more recent answer (written by Matt Connolly) suggests:

git reset HEAD^ path/to/file/to/revert

HEAD^ allows the file to access its content in the previous commit before the last one.

Then you can git commit --amend, as I originally wrote below.


With Git 2.23 (August 2019), you might use the new git restore command

 git restore --source=HEAD^ --staged  -- path/to/file/to/revert

shorter:

 git restore -s@^ -S -- path/to/file/to/revert

Again, you then can git commit --amend, as I originally wrote below.


Original answer (January 2011)

If this is your last commit (and you haven't pushed it anywhere), you can amend it:
(first stash or save b)

 git commit --amend

Then delete b, re-commit. Restore b and you're done.

--amend

Used to amend the tip of the current branch.
Prepare the tree object you would want to replace the latest commit as usual (this includes the usual -i/-o and explicit paths), and the commit log editor is seeded with the commit message from the tip of the current branch.
The commit you create replaces the current tip — if it was a merge, it will have the parents of the current tip as parents — so the current top commit is discarded.

2 of 6
79
  1. git diff --name-only HEAD^ - (optional) use to list the files that changed in the last commit.
  2. git reset HEAD^ path/to/file/to/revert - to reset the index to that last version, leaving the working copy untouched.
  3. git commit --amend - to amend that last commit to include the index changes
🌐
LabEx
labex.io › tutorials › git-how-to-revert-a-git-commit-without-losing-changes-415168
How to revert a Git commit without losing changes | LabEx
For example, you might want to fix a mistake in the commit rather than discarding it entirely. The --no-commit (or -n) option is perfect for this. First, let's reset our repository to the state before our last revert, so we can try a different ...
🌐
Stackfindover
blog.stackfindover.com › home › undoing ‘git add’ before commit in git: a step-by-step guide
Undoing 'Git Add' Before Commit in Git: A Step-by-Step Guide
January 8, 2026 - You can use the ‘git status’ command to view the current status of your changes. To unstage specific files, use the ‘git reset HEAD <file>’ command followed by the filename. This command removes the specified file from the staging area ...