如何从存储库中删除“file1.txt”?


当前回答

使用git rm。

如果要从Git存储库和文件系统中删除文件,请使用:

git rm file1.txt
git commit -m "remove file1.txt"

但如果您只想从Git存储库中删除文件,而不想从文件系统中删除,请使用:

git rm --cached file1.txt
git commit -m "remove file1.txt"

并将更改推送到远程回购

git push origin branch_name

其他回答

更一般地,git help至少可以帮助解决以下简单问题:

zhasper@berens:/media/Kindle/documents$ git help
usage: git [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path] [-p|--paginate|--no-pager] [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE] [--help] COMMAND [ARGS]

The most commonly used git commands are:
   add        Add file contents to the index
   :
   rm         Remove files from the working tree and from the index

使用git rm。

如果要从Git存储库和文件系统中删除文件,请使用:

git rm file1.txt
git commit -m "remove file1.txt"

但如果您只想从Git存储库中删除文件,而不想从文件系统中删除,请使用:

git rm --cached file1.txt
git commit -m "remove file1.txt"

并将更改推送到远程回购

git push origin branch_name

删除特定文件

git-rm文件名

在一次快照中递归清理目录中所有未跟踪的文件

git-clean-fdx

只需打开github存储库中的文件,就可以看到Raw|Blame旁边的删除图标,不要忘记单击提交更改按钮。您可以看到您的文件已被删除。

转到项目目录并键入:

git filter-branch --tree-filter 'rm -f <deleted-file>' HEAD

在推送之后,强制从所有提交中删除文件。

git push origin --force --all