In order to understand the man page of git rm
you need to understand how the staging area (i.e. index) and git status
work.
You can think of working tree, staging area and commit referenced by head as three folders with the same content in a clean situation (i.e. git status
shows no diff):
Working Staging HEAD
--------- --------- ------
a a a
The question is how git status
detect changes?:
- unstaged changes: diff between Working and Staging
- staged changes: diff between Staging and HEAD
When you execute rm a
, you are removing a only from the working copy, obtainin this:
Working Staging HEAD
--------- --------- ------
- a a
git status
detect one unstaged change because there is a difference between working and staging, and no staged changes since there is no difference between staging and HEAD
When you execute git rm a
, as the documentation states, a
is removed also from the staging area, resulting in:
Working Staging HEAD
--------- --------- ------
- - a
Which allows git status
to detect one staged change and no unstaged changes.
Following this way of thinking you can understand some other commands suggested by git status itself:
git add <file>...
- to update what will be committed, i.e. copy file from working to staging
git-commit
- Record changes to the repository, i.e. copy every file from staging to HEAD (also creates a new commit and moves HEAD)
git checkout -- <file>...
to discard changes in working directory, i.e. copy from staging to working copy
git reset HEAD <file>
to unstage, i.e. copy from HEAD to staging
As a side note, git rm --cached a
will result in this:
Working Staging HEAD
--------- --------- ------
a - a
Git status will show the removal of a
as staged for commit, since there is a difference between staging and head, but also a
as untracked: there is a difference between working and staging, but since the file is missing from the staging area, git status detects it as untracked file instead of unstaged change