正在从 git 中删除大文件

Removing large files from git

这是我之前 post here 的后续。 我正在尝试删除我提交给 git 的一个大文件。根据我之前post的建议,我尝试了

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.

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

Cannot rewrite branches: Your index contains uncommitted changes.

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

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

git reset --hard HEAD


@torek mentioned in the comment below and as per GitHub help page,不建议在filter-branch

前使用stash

Warning: If you run git filter-branch after stashing changes, you won't be able to retrieve your changes with other stash commands. Before running git filter-branch, we recommend unstashing any changes you've made.

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


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

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