How to remove a file from the staging area (= index = cache) in Git?
Solution 1:
You want:
git rm --cached [file]
If you omit the --cached
option, it will also delete it from the working tree. git rm
is slightly safer than git reset
, because you'll be warned if the staged content doesn't match either the tip of the branch or the file on disk. (If it doesn't, you have to add --force
.)
Solution 2:
This should unstage a <file> for you (without removing or otherwise modifying the file):
git reset <file>
Solution 3:
git reset HEAD <file>
for removing a particular file from the index.
and
git reset HEAD
for removing all indexed files.