github push失败,删除git历史中的大文件
转移 repo 的时候,直接 push 会报错文件大小受到限制,但是这个文件只存在于 commit history,并不在实际文件中。
1. 找出 history 中的大文件
参考:https://stackoverflow.com/questions/10622179/how-to-find-identify-large-commits-in-git-history
1 2 3 4 5 6
| git rev-list --objects --all | git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' | sed -n 's/^blob //p' | sort --numeric-sort --key=2 | cut -c 1-12,41- | $(command -v gnumfmt || echo numfmt) --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest
|
2. 使用 BFG 删除
参考:https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/removing-sensitive-data-from-a-repository
3. 清理缓存
1
| git reflog expire --expire=now --all && git gc --prune=now --aggressive
|
4. 强制推上 GitHub
注意:强制推送会改写远程历史,操作前请确认没有其他人依赖该分支。