我有一个 git 存储库,有一个程序,很久以前我不小心在其中添加了一堆视频。视频本身早就被删除了,我从 git ( git rm ExampleResult) 中删除了它们(它们都在 ExampleResult 文件夹中)。但是当我尝试将其全部上传到 github 时出现了问题,因为现在存储库重约 90 GB,并且需要很长时间才能对其进行任何操作。(我放弃了推动压缩对象线)。可以做些什么来解决这个问题。
git ls-files 给出
.gitignore
README.md
config.py
main.py
requirements.txt
video_divider.py
过滤尝试:
(venv) git filter-branch --tree-filter 'rm -rf *.mp4' HEAD
WARNING: git-filter-branch has a glut of gotchas generating mangled history
rewrites. Hit Ctrl-C before proceeding to abort, then use an
alternative filtering tool such as 'git filter-repo'
(https://github.com/newren/git-filter-repo/) instead. See the
filter-branch manual page for more details; to squelch this warning,
set FILTER_BRANCH_SQUELCH_WARNING=1.
Proceeding with filter-branch...
usage: git filter-branch [--setup <command>] [--subdirectory-filter <directory>] [--env-filter <command>]
[--tree-filter <command>] [--index-filter <command>]
[--parent-filter <command>] [--msg-filter <command>]
[--commit-filter <command>] [--tag-name-filter <command>]
[--original <namespace>]
[-d <directory>] [-f | --force] [--state-branch <branch>]
[--] [<rev-list options>...]
据我了解,这意味着该命令未执行。.git 文件夹仍小于 100 GB。
我还尝试删除所有文件所在的整个 ExampleResult 目录,但没有成功。
>git filter-branch --index-filter 'git rm -r --cached --ignore-unmatch ExampleResult' HEAD
fatal: ambiguous argument 'rm': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
这是因为历史有这个条目,而 Git “必须”在
push. 因此,您需要将它们从历史记录中删除:git filter-branch --tree-filter 'rm -rf *.avi' HEAD在哪里:
-rf 递归和强制
-avi 文件扩展名,你猜对了。
随后
push的 -s 应该排除这些文件