当我像这样删除文件时
git rm file_name.ext
我必须提交这些更改吗?为什么?
如果我必须提交,我会这样做吗?
git commit . -m "Delete file_name.txt"
这就是我问的原因:我在 Git 的暂存索引中添加了错误的文件
git add wrong_file.txt
所以我删除了它
git reset HEAD wrong_file.txt
但这样做之后,我注意到了这条消息
$ git reset HEAD wrong_file.txt
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# deleted: test2.txt
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# wrong_file.txt
$
当我将正确的文件添加到暂存索引时,我注意到我删除的 test2.txt 文件被重命名为 right_file.txt
$ touch right_file.txt && git add right_file.txt
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# renamed: test2.txt -> right_file.txt
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# wrong_file.txt
$