前言
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
再次強制推送就可以啦