首页 > 解决方案 > 从 git 中删除大文件

问题描述

这是对我之前的帖子的跟进。我正在尝试删除我提交给 git 的大文件。根据我上一篇文章中给出的建议,我尝试了

git filter-branch --force --index-filter "git rm --cached --ignore-unmatch folder/Unconfirmed 866711.crdownload" --prune-empty --tag-name-filter cat -- --all

按照上述命令,我尝试推送所有更改

git push origin --force --all

但是,我得到了使用之前显示的相同错误filter-branch

remote: error: File folder/Unconfirmed 866711.crdownload is 486.30 MB; this exceeds GitHub's file size limit of 100.00 MB

或者,我也尝试过

git add --all

git filter-branch -f --index-filter "git rm --cached --ignore-unmatch folder/Unconfirmed 866711.crdownload" HEAD

但是,我得到以下

Cannot rewrite branches: Your index contains uncommitted changes.

我不确定我是否错过了任何命令或标志。有什么建议么?

标签: gitgithubgithub-for-windows

解决方案


无法重写分支:您的索引包含未提交的更改。

您的工作目录中有未提交的更改,即为提交暂存的更改(检查git status输出)。如果您愿意,可以提交这些更改,或者使用stash保留这些未提交的更改,并在执行命令后应用它们filter-branch

如果您不想要未提交的更改,则可以执行硬重置。

git reset --hard HEAD


正如下面评论中提到的@torek和 GitHub 帮助页面,不建议在stash此之前使用filter-branch

警告:如果您在存储更改后运行 git filter-branch,您将无法使用其他存储命令检索您的更改。在运行 git filter-branch 之前,我们建议取消隐藏您所做的任何更改。

因此,如果您想保留未提交的更改,请提交更改。然后继续执行filter-branch命令。


您的filter-branch命令缺少单引号(以说明要删除的文件名中的空格)

git filter-branch -f --index-filter "git rm --cached --ignore-unmatch 'folder/Unconfirmed 866711.crdownload'" HEAD

推荐阅读