什么时候使用 git rm -f ?
我正在学习 Git,无法理解在发出“git rm”命令时使用 -f 标志的条件。请解释一下需要 rm -f 而不是仅 rm 的情况?
I am learning Git and am unable to understand under what condition the -f flag is used while issuing the "git rm" command. Please explain a scenario where rm -f would be required instead of rm only?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
说明:
如果文件不是您上次签出的提交的最新文件,则使用
-f
删除该文件。这是为了防止您删除已进行更改但尚未签入的文件。示例:
您签出包含文件 sample.txt 的提交 0a12d4。在更改任何文件之前,您可以使用
git rm example.txt
删除 sample.txt。但是,一旦对 sample.txt 进行更改,您将需要使用git rm -f example.txt
删除该文件Explanation:
The
-f
is used to remove a file if the file is not up to date with your last checked out commit. It is to prevent you from removing a file that you have made changes to, but have not yet checked them in.Example:
You check out commit 0a12d4 that contains the file sample.txt. Before you change any files, you could remove the sample.txt with
git rm sample.txt
. However, once you make a change to sample.txt, you would need to usegit rm -f sample.txt
to remove the file如果您尝试
git rm
一个包含未暂存更改的文件,并且不提供-f
标志,则会失败:If you try to
git rm
a file that has unstaged changes, it fails if you don't provide the-f
flag:如果您编辑一个文件,然后意识到您想要删除它。
现在想想,我真的很想删掉它……
If you edit a file, and then realize you want to delete it instead.
Now that I think about it, I actually want to delete it...