有一个使用git删除文件的首选方法吗?


Is there a preferred method of deleting a file with git?

本问题已经有最佳答案,请猛点这里访问。

假设您要重构代码并决定删除其中一个源文件,但您可能希望检索需要该文件的早期提交。有没有一个首选的方法来消除文件,以尽量减少检索旧版本的工作?


只需使用git rm FILENAME

NAME

git-rm - Remove files from the working tree and from the index

SYNOPSIS

git rm [-f | --force] [-n] [-r] [--cached] [--ignore-unmatch]
[--quiet] [--] …?

DESCRIPTION

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. (There is no option to remove a file
only from the working tree and yet keep it in the index; use /bin/rm
if you want to do that.) The files being removed have to be identical
to the tip of the branch, and no updates to their contents can be
staged in the index, though that default behavior can be overridden
with the -f option. When --cached is given, the staged content has to
match either the tip of the branch or the file on disk, allowing the
file to be removed from just the index.