The question is not clearly posed. The reason is that git add
has two meanings:
- adding a new file to the staging area, then undo with
git rm --cached file
.
- adding a modified file to the staging area, then undo with
git reset HEAD file
.
If in doubt, use
git reset HEAD file
Because it does the expected thing in both cases.
Warning: if you do git rm --cached file
on a file that was modified (a file that existed before in the repository), then the file will be removed on git commit
! It will still exist in your file system, but if anybody else pulls your commit, the file will be deleted from their work tree.
git status
will tell you if the file was a new file or modified:
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: my_new_file.txt
modified: my_modified_file.txt