According to git rm doc ,
Remove files from the index, or from the working tree and the index. git rm will not remove a file from just your working directory.
Also,
--cached : Use this option to unstage and remove paths only from the index. Working tree files, whether modified or not, will be left alone.
Now , I found a difference in the way they are changing working tree and index where I feel it does not matches the definition above.
First I ran git rm --cached
and I saw this :
$ git rm --cached src/main/java/com/kang/pagination/PaginationResult.java
rm 'src/main/java/com/kang/pagination/PaginationResult.java'
$ git status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
(use "git push" to publish your local commits)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
deleted: src/main/java/com/kang/pagination/PaginationResult.java
Untracked files:
(use "git add <file>..." to include in what will be committed)
src/main/java/com/kang/pagination/PaginationResult.java
We can see the change as untracked file and in staged area.
Why we have file in untracked area when the file change is in staging area ?
Instead of that , If I had ran git rm
, this is what I would got :
$ git rm src/main/java/com/kang/pagination/PaginationResult.java
rm 'src/main/java/com/kang/pagination/PaginationResult.java'
$ git status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
(use "git push" to publish your local commits)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
deleted: src/main/java/com/kang/pagination/PaginationResult.java
Note that here we don't have untracked file. Why ?