git rm –cached and 'deleted' status

I am wondering why when I do:

git add <file>

and after that, I do:

  • How to manage branches with Kiln using Git?
  • How best to handle Git Deployment For multiple web servers
  • In rebase conflicts, how to say “use file from branch A, blow away file from master”?
  • Git revert does not work as expected
  • How do you track the build count of your library when there are multiple authors using version control?
  • Code Review with Git inside Visual Studio 2015
  • git rm --cached <file>
    

    The file remains in deleted status in the stage área.

    Here the example:
    enter image description here

    I am only looking for an explanation about the ‘deleted’ status on the file.

    Thanks

  • Why am I getting an empty repo when cloning my keystone app to local repo from heroku?
  • How can I automatically update Perl modules' $VERSION with Git?
  • Nested and independent GIT repos, for Backup, how?
  • Moving a git subtree into different repository
  • Git remote url with username in form of email address
  • Document about files in .git/rebase-apply directory?
  • 2 Solutions collect form web for “git rm –cached and 'deleted' status”

    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>
    
    Git Baby is a git and github fan, let's start git clone.