前言
GitHub仓库单个文件的推荐大小不能超过50MB(仅限于警告),但绝对不能超过100MB(拒绝提交)
问题
人总有手贱的时候,一不小心往Git仓库拷贝大文件并尝试push到GitHub,发现报错后才意识到问题
这个时候无论怎么样push都不会成功的,即使用git执行delete操作也无济于事,因为改动记录保存在.git里边,有相关文件的历史版本记录
解决
方法一
保证本地没有改动,使用git filter-branch
删除git缓冲区里边的大文件
git filter-branch --force --index-filter "git rm --cached --ignore-unmatch node_modules/puppeteer/.local-chromium/win64-686378/chrome-win/chrome.dll \
node_modules/puppeteer/.local-chromium/win64-686378/chrome-win/chrome_child.dll \
node_modules/puppeteer/.local-chromium/win64-686378/chrome-win/interactive_ui_tests.exe" --prune-empty --tag-name-filter cat -- --all
然后强制推送到远程仓库,如果报错的话,可以试试方法二
git push -f
方法二
通过python安装git-filter-repo包
pip install git-filter-repo
强制删掉相关文件
git filter-repo --path node_modules/puppeteer/.local-chromium/win64-686378/chrome-win/chrome.dll \
> --path node_modules/puppeteer/.local-chromium/win64-686378/chrome-win/chrome_child.dll \
> --path node_modules/puppeteer/.local-chromium/win64-686378/chrome-win/interactive_ui_tests.exe \
> --invert-paths --force
再次提交发现报错,大概是丢失remote的链接了
于是乎,添加remote url绑定
git remote add origin https://github.com/hywing/xxx.git
再次强制推送就可以啦