git rm –cached and 'deleted' status
I am wondering why when I do:
git add <file>
and after that, I do:
git rm --cached <file>
The file remains in deleted status in the stage área.
Here the example:
I am only looking for an explanation about the ‘deleted’ status on the file.
2 Solutions collect form web for “git rm –cached and 'deleted' status”
git reset HEAD yourFile, instead of a
git rm --cached.
A mixed reset will remove your file from the index, without removing it from the working tree.
See “Undo ‘
git add‘ before commit”.
In your case, a
git stash would need to precede the
git reset, and then a
git stash pop would restore your changes in progress, after the reset.
Regarding the ‘
deleted‘ status after a
git rm --cached, that command registers in the index the deletion of the file, which is why you see it recorded as ‘deleted’ for the next commit.
The OP Ferpega insists:
I am asking why the deleted status is there as resulting of
git rm --cachedbecause this command should has the same behavior than
git reset HEAD <file>as you can see in
Well, no, a
git rm has not the same behavior as a [
Both will affect the index, but:
- one (the
git rm) will record a file for deletion on the next commit, hence the ‘
- the other (
git reset) will copy HEAD to the index, resetting said index back to what the file was in HEAD.
You added the file to the index/cached (green in your screenshot) and told get you wanted to remove the file. Index/cache changes are only executed when a commit is done.
I’m thinking you probably put a file in the index/cache and then wanted to remove it (so it would not be committed).
The command to do this is in the message
git status gives you (right above the circled
git reset HEAD <filename>