git reset -- FILE_NAME will do it.
See the git reset manual:
Answer from Christoffer Hammarström on Stack OverflowThis means that
git reset <pathspec>is the opposite ofgit add <pathspec>
git reset -- FILE_NAME will do it.
See the git reset manual:
This means that
git reset <pathspec>is the opposite ofgit add <pathspec>
git stash save
git stash apply
they will all be unstaged
I just clicked on the source control and I clicked the initialize git option ig
How do I undo the last commit without losing changes?
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
How to Undo git add and git Commit Before Push
New to git, advice needed. Revert commit but keep changes
How to Undo "git add"
What happens if I undo a `git add`, and then make additional changes?
Can I undo the last `git restore` command?
Videos
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.
git diff --name-only HEAD^- (optional) use to list the files that changed in the last commit.git reset HEAD^ path/to/file/to/revert- to reset the index to that last version, leaving the working copy untouched.git commit --amend- to amend that last commit to include the index changes