git - 从 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.
我不确定我是否错过了任何命令或标志。有什么建议么?
解决方案
无法重写分支:您的索引包含未提交的更改。
您的工作目录中有未提交的更改,即为提交暂存的更改(检查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
推荐阅读
- node.js - Nodejs Redis hdel 不会删除密钥
- javascript - 关于 html/css/js 可折叠内容的问题
- fullcalendar - 是否可以调整全日历的宽度
- bash - 将功能分支合并到 master 以启用 git LFS (git) 后如何建议开发人员
- mysql - 在mysql中创建子查询
- arrays - 从 C 中的数组中消除 NaN 值
- docker - 通过参数化构建多个 Docker Hub
- arrays - 新数组,派生自另一个指向字符串的指针数组,只是顺序不同(在 C 中)
- java - 当您尝试去混淆奇怪的代码时如何处理名称冲突?
- javascript - 在 JS 中获取属性