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.
Thanks
Try a 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 --cached
because this command should has the same behavior thangit reset HEAD <file>
as you can see ingit rm
.
Well, no, a git rm
has not the same behavior as a [git reset][8]
.
Both will affect the index, but:
git rm
) will record a file for deletion on the next commit, hence the 'deleted
' status,git reset
) will copy HEAD to the index, resetting said index back to what the file was in HEAD.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With