git - 从提交历史中删除错误提交的大文件

标签 git

如何从提交历史中删除错误提交的大文件?在我删除有问题的文件之前,Git 不会再将提交推送到远程。从那以后我试图删除它们,但它们存在于以前的提交中。

备注 : 我在项目中不再需要大文件了。

git push origin my-branch我得到:

remote: warning: File public/images/reserve_assets/myfile.tif is 63.60 MB; this is larger than GitHub's recommended maximum file size of 50.00 MB
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
remote: error: Trace: 0c08ce8916353c82c7328a241a40c8ca
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File public/images/reserve_assets/myotherfile.tif is 107.34 MB; this exceeds GitHub's file size limit of 100.00 MB

然后
! [remote rejected] my-branch -> my-branch (pre-receive hook declined)
error: failed to push some refs to 'git@github.com:RepoOwner/myrepo.git'

我试过 git filter-branch --tree-filter 'rm -f myfile.tif' HEAD它在提交历史中执行重写。它输出
Rewrite 1cd9b031d047d4270ff8b488b3b5e8db2905c687 (87/93) (12 seconds passed, remaining 0 predicted)

但是接着说WARNING: Ref 'refs/heads/my-branch' is unchanged .似乎它正在重写并从历史中删除,但我仍然无法 push 。

最佳答案

我还有其他很大的文件。您不能通过 git filter-branch --tree-filter 'rm -rf path/to/your/file' HEAD 一次删除一个文件因为每次它都会创建一个备份。

通过 git filter-branch -f --tree-filter 'rm -rf path/to/folder' HEAD 删除整个有问题的文件夹附加 -f强制以前的备份重写可以解决问题(假设您以前尝试过删除单个文件)

关于git - 从提交历史中删除错误提交的大文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55584017/

相关文章:

GIT预接收 Hook

php - 如何使用符号链接(symbolic link)的 Composer 包进行开发,但从 vcs 存储库构建?

node.js - 从 Node.js 应用程序管理 git 存储库

Git 历史报告

git diff --缓存: unknown option `cached'

eclipse - egit 不显示标签装饰

git - 如何减少推送子树的时间不断增加?

git - 如果我在本地有 10 个分支,如何将它们推送到远程源服务器?

git - 如何将所有当前未跟踪的文件/文件夹添加到 git ignore?

git - merge 时跳过特定的提交