我正在尝试使用 git push origin <branchname>
将我的本地分支推送到我的源分支。我得到一个:
remote: error: File app/assets/images/title00.mp4 is 297.77 MB;
错误,抱怨我超过了GitHub允许的文件大小。
它抱怨的文件不再在我的版本控制中,因为我删除了它,因为它太大了。
因此,当我尝试遵循 Git 文档的建议时
git rm <path-to-large-file>
我收到以下错误:
fatal: pathspec 'app/assets/images/title00.mp4' did not match any files
知道我应该怎么做吗?
来自重写历史 Git 文档:
从每次提交中删除文件
这种情况相当普遍。有人不小心用一个轻率的
git add .
提交了一个巨大的二进制文件,你想在任何地方删除它。也许您不小心提交了一个包含密码的文件,并且您想使您的项目开源。filter-branch
是您可能想要用来清理整个历史记录的工具。要从整个历史记录中删除名为passwords.txt
的文件,可以使用--tree-filter
选项filter-branch
:
$ git filter-branch --tree-filter 'rm -f passwords.txt' HEAD
Rewrite 6b9b3cf04e7c5686a9cb838c3f36a8cb6a0fc2bd (21/21)
Ref 'refs/heads/master' was rewritten
在您的方案中,您可能希望执行以下操作:
git filter-branch --tree-filter 'rm -f app/assets/images/title00.mp4' HEAD
您可以使用出色的 BFG 存储库清理器从存储库历史记录中清除文件。基本上,您可以运行以下步骤
第一。 安装bfg清洁器。在MacOSX中,使用brew install bfg
.
其次,从历史记录中清除文件。
git clone --mirror git@github.com:your_github_user/your_github_repo.git
bfg --delete-files title00.mp4 your_github_repo.git
cd your_github_repo.git
git reflog expire --expire=now --all && git gc --prune=now --aggressive
git push
然后,您必须清除非镜像reper(您的开发文件夹)并从github再次克隆它,以避免重新推送大文件。
git clone git@github.com:your_github_user/your_github_repo.git
显然,BFG网站上提供了更多信息。