Git rm - saved and deleted status

I am wondering why when I do this:

git add <file> 

and after that I:

 git rm --cached <file> 

The file remains in the status deleted at the stage .

Here is an example: enter image description here

I'm just looking for an explanation of the status of 'deleted' in a file.

thanks

+6
source share
2 answers

Try git reset HEAD yourFile instead of git rm --cached .

A mixed reset will remove your file from the index without deleting it from the working tree.
See " Undo" git add "before commit ."

In your case, git stash should be preceded by git reset , and then git stash pop will restore your changes in the process, after reset.


As for the state <<26> after git rm --cached , this command registers file deletion in the index, which is why you see that it is recorded as โ€œdeletedโ€ for the next commit.

OP Ferpega insists :

I ask why the remote status exists as a result of git rm --cached , because this command should have the same behavior as git reset HEAD <file> , as you can see in git rm .

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

  • one ( git rm ) will write the file for deletion at the next commit, therefore, status <<26>,
  • the other ( git reset ) will copy HEAD to the index, dropping the specified index back to the file that was in HEAD.
+6
source

You added the file to the index / cached (green in the screenshot) and said that you want to delete the file. Index / cache changes are performed only when committing.

I think that you probably put the file in the index / cache and then want to delete it (so that it is not committed).

The command for this in the git status message gives you (right above the deleted circle.

 git reset HEAD <filename> 
0
source

All Articles