git rm 和 git rm -f 有什么区别?

What is the difference between git rm and git rm -f?

我正在阅读书 Git Pro,它说:

To remove a file from Git, you have to remove it from your tracked files (more accurately, remove it from your staging area) and then commit. The git rm command does that, and also removes the file from your working directory so you don’t see it as an untracked file the next time around.

下一段谈到 git rm -f

If you modified the file and added it to the staging area already, you must force the removal with the -f option. This is a safety feature to prevent accidental removal of data that hasn’t yet been recorded in a snapshot and that can’t be recovered from Git.

我不明白的是在这两个段落中,他们在谈论从同一区域删除文件(staging 我猜,git 添加屏幕截图的地方git add . 之后)。

如果这两个命令都用于从暂存区删除文件,那么有什么区别?

git rm -f(或--force)覆盖最新检查。如果未提供 -fgit rm 将拒绝删除自上次提交后修改的文件,但 git rm -f 将继续删除。

$ git init
Initialized empty Git repository in /home/ibug/test/.git/
$ touch foo
$ git add foo
$ git rm foo
error: the following file has changes staged in the index:
    foo
(use --cached to keep the file, or -f to force removal)
$ git commit --message "Test foo"
[master (root-commit) 1234567] Test foo
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 foo
$ git rm foo
rm 'foo'
$