Git 有两种选择:
如果文件在索引中没有进行任何更改:Git 有两种选择:,git,git-rm,Git,Git Rm,如果文件在索引中没有进行任何更改: bykov@gitserver:~/temp> git rm file1.txt bykov@gitserver:~/temp> git commit -m "remove file1.txt" 如果文件在索引中有暂存的更改: bykov@gitserver:~/temp> git rm -f file1.txt bykov@gitserver:~/temp> git commit -m "remove file1.txt" 此
bykov@gitserver:~/temp> git rm file1.txt
bykov@gitserver:~/temp> git commit -m "remove file1.txt"
bykov@gitserver:~/temp> git rm -f file1.txt
bykov@gitserver:~/temp> git commit -m "remove file1.txt"
此外,如果是要删除的文件夹及其后续子文件夹或文件,请使用:
git rm -r foldername
如果要使用rm命令从本地文件夹中删除文件,然后将更改推送到远程服务器,请使用另一种方法
rm file1.txt
git commit -a -m "Deleting files"
git push origin master
在我的例子中,我尝试在几次提交后删除github上的文件,但在计算机上保存
git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch file_name_with_path' HEAD
git push --force -u origin master
后来,该文件被忽略以删除特定文件 git-rm文件名 一次清除目录中所有未跟踪的文件 git-clean-fdx
git commit -m "unwanted files or some inline comments"
git push
gitrm-r文件名
或者,只从本地存储库中删除文件,而从文件系统中删除文件
git rm--缓存文件名
git commit -m "unwanted files or some inline comments"
git push
git commit -m "unwanted files or some inline comments"
git push
若你们并没有在本地回购中归档,而是在git回购中归档,那个么只需通过web界面在git回购中打开文件,然后在界面的右角找到删除按钮。
git rm
从现在起将只删除此分支上的文件,但它将保留在历史中,git将记住它
正确的方法是使用git过滤器分支
,正如其他人在这里提到的那样。它将重写分支历史记录中的每个提交以删除该文件
但是,即使这样做了,git也可以记住它,因为在reflog、remotes、tags等等中可以有对它的引用
如果您想在一个步骤中完全消除它,我建议您使用git-forget-blob
这很简单,只要做git忘记blob file1.txt
这将删除所有引用,执行git筛选器分支,最后运行git垃圾收集器,以在您的repo中完全删除此文件。我尝试了很多建议的选项,但似乎都不起作用(我不会列出各种问题)。 我最终所做的工作(对我来说)简单直观:
我有obj和bin文件,它们意外地进入了回购协议,我不想污染我的“更改文件”列表 在我注意到他们去了遥控器后,我将其添加到
.gitignore
/*/obj
/*/bin
问题是它们已经在远程中,当它们被更改时,它们会弹出为已更改,并污染已更改的文件列表
要停止查看它们,您需要从远程存储库中删除整个文件夹
git commit -m "unwanted files or some inline comments"
git push
在命令提示符中:
C:\repos\MyRepo
)C:\repos\MyRepo\SSIS
)git rm-r-f obj
- rm=删除
- -r=递归删除
- -f=意味着力量,因为你是认真的
- obj是文件夹
然后因为我不想查命令行,我进入Visual Sstudio并进行了同步,将其应用于远程在您使用git rm从回购中删除文件后,您可以使用它从回购历史中完全轻松地删除该文件。注意:如果您只想从git中删除文件,请使用以下命令:
git rm --cached file1.txt
如果要同时从硬盘中删除,请执行以下操作:
git rm file1.txt
如果要删除文件夹(该文件夹可能包含少量文件),则应使用递归命令删除,如下所示:
git rm -r foldername
如果要删除另一个文件夹中的文件夹
git rm -r parentFolder/childFolder
然后,您可以像往常一样commit
和push
。但是,如果要恢复已删除的文件夹,可以执行以下操作:
来自文档:
git rm [-f | --force] [-n] [-r] [--cached] [--ignore-unmatch] [--quiet] [--] <file>…
git push origin --force --tags
可能需要逃离他们。前导目录名(例如dir to
可以指定remove dir/file1和dir/file2)来删除中的所有文件
目录和递归的所有子目录,但这需要
要显式指定的-r选项。
-f
--force
Files to remove. Fileglobs (e.g. *.c) can be given to remove all matching files. If you want Git to expand file glob characters, you
Override the up-to-date check.
Don’t actually remove any file(s). Instead, just show if they exist in the index and would otherwise be removed by the command.
Allow recursive removal when a leading directory name is given.
Use this option to unstage and remove paths only from the index. Working tree files, whether modified or not, will be left alone.
git rm normally outputs one line (in the form of an rm command) for each file removed. This option suppresses that output.
-n
--试运行
Files to remove. Fileglobs (e.g. *.c) can be given to remove all matching files. If you want Git to expand file glob characters, you
Override the up-to-date check.
Don’t actually remove any file(s). Instead, just show if they exist in the index and would otherwise be removed by the command.
Allow recursive removal when a leading directory name is given.
Use this option to unstage and remove paths only from the index. Working tree files, whether modified or not, will be left alone.
git rm normally outputs one line (in the form of an rm command) for each file removed. This option suppresses that output.
-r
Files to remove. Fileglobs (e.g. *.c) can be given to remove all matching files. If you want Git to expand file glob characters, you
Override the up-to-date check.
Don’t actually remove any file(s). Instead, just show if they exist in the index and would otherwise be removed by the command.
Allow recursive removal when a leading directory name is given.
Use this option to unstage and remove paths only from the index. Working tree files, whether modified or not, will be left alone.
git rm normally outputs one line (in the form of an rm command) for each file removed. This option suppresses that output.
--
This option can be used to separate command-line options from the list of files, (useful when filenames might be mistaken for
命令行选项)。
--cached
Files to remove. Fileglobs (e.g. *.c) can be given to remove all matching files. If you want Git to expand file glob characters, you
Override the up-to-date check.
Don’t actually remove any file(s). Instead, just show if they exist in the index and would otherwise be removed by the command.
Allow recursive removal when a leading directory name is given.
Use this option to unstage and remove paths only from the index. Working tree files, whether modified or not, will be left alone.
git rm normally outputs one line (in the form of an rm command) for each file removed. This option suppresses that output.
--忽略不匹配
Exit with a zero status even if no files matched.
-q
--quiet
Files to remove. Fileglobs (e.g. *.c) can be given to remove all matching files. If you want Git to expand file glob characters, you
Override the up-to-date check.
Don’t actually remove any file(s). Instead, just show if they exist in the index and would otherwise be removed by the command.
Allow recursive removal when a leading directory name is given.
Use this option to unstage and remove paths only from the index. Working tree files, whether modified or not, will be left alone.
git rm normally outputs one line (in the form of an rm command) for each file removed. This option suppresses that output.
如果需要从确定的扩展名(例如,已编译文件)中删除文件,可以执行以下操作一次删除所有文件:
git remove -f *.pyc
据报道
git-rm——缓存的file1.txt
对于敏感数据,最好不要说您删除了该文件,而只是将其包含在最后一次已知的提交中:
0。修改上次提交
git commit --amend -CHEAD
如果要从所有git历史记录中删除该文件,根据,应执行以下操作: 1。将其从本地历史记录中删除
git filter-branch --force --index-filter \ "git rm --cached --ignore-unmatch PATH-TO-YOUR-FILE-WITH-SENSITIVE-DATA" \ --prune-empty --tag-name-filter cat -- --all
# Replace PATH-TO-YOUR-FILE-WITH-SENSITIVE-DATA with the path to the file you want to remove, not just its filename
git push origin --force --all
4.如果您还需要将其从标签发布中删除:
git rm [-f | --force] [-n] [-r] [--cached] [--ignore-unmatch] [--quiet] [--] <file>…
git push origin --force --tags
只需在github repos中查看文件即可