1.查看哪個文件過大了
報錯信息:
remote: Resolving deltas: 100% (24/24), completed with 3 local objects.
remote: warning: File CPT_0707_ao/temp_past/temp2/deltap.csv is 71.69 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: c42ade10239deffc45c2a2800135e242
remote: error: See http://git.io/iEPt8g for more information.
To https://github.com/******
! [remote rejected] master -> master (pre-receive hook declined)
可以發現,是CPT_0707_ao/temp_past/temp2/deltap.csv 文件太大,超過了50Mb的限制。那么要處理的就是這個文件了。
2.重寫commit,刪除大文件
git filter-branch --force --index-filter 'git rm -rf --cached --ignore-unmatch CPT_0707_ao/temp_past/temp2/deltap.csv' --prune-empty --tag-name-filter cat -- --all
\(\color{red}{P.S.}\)如果報錯:
Cannot rewrite branches: Your index contains uncommitted changes.
解決:
git stash
3.推送修改后的repo
git push origin master --force
4.清理和回收空間
雖然上面我們已經刪除了文件, 但是我們的repo里面仍然保留了這些objects, 等待垃圾回收(GC), 所以我們要用命令徹底清除它, 並收回空間,命令如下:
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --prune=now
徹底解決。
引用:https://blog.csdn.net/qq997843911/article/details/88979051