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.

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 than git reset HEAD <file> as you can see in git rm .

Well, no, a git rm has not the same behavior as a [ git reset][8] .
Both will affect the index, but:

  • one (the git rm ) will record a file for deletion on the next commit, hence the ' deleted ' status,
  • 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 deleted .

    git reset HEAD <filename>
    
    链接地址: http://www.djcxy.com/p/6178.html

    上一篇: restrict关键字在C ++中的含义是什么?

    下一篇: 缓存和“删除”状态