清理.git文件

查找.git中的大文件

  1. cd 到工程文件
  2. 查找十个大文件并降序排序
git rev-list --objects --all | grep "$(git verify-pack -v .git/objects/pack/*.idx | sort -k 3 -n | tail -10 | awk '{print$1}')"

命令执行结果如下图:


WeChat054336bc1f02068bb7a4bb9fb717be5a.png

删除文件

git filter-branch --index-filter 'git rm --cached --ignore-unmatch sdk/GPUImage/Debug-iphoneos/GPUImage.framework/GPUImage' -- --all

如果删除命令执行错误如下:

WARNING: git-filter-branch has a glut of gotchas generating mangled history
     rewrites.  Hit Ctrl-C before proceeding to abort, then use an
     alternative filtering tool such as 'git filter-repo'
     (https://github.com/newren/git-filter-repo/) instead.  See the
     filter-branch manual page for more details; to squelch this warning,
     set FILTER_BRANCH_SQUELCH_WARNING=1.
Proceeding with filter-branch...

Cannot rewrite branches: You have unstaged changes.

这是当前分支有未提交的代码,提交完成后再执行删除代码即可。

最后清理远端

rm -Rf .git/refs/original
rm -Rf .git/logs/
git gc
git prune
git push -f
注意:通过此方法清理后会导致库文件丢失,慎重选择

你可能感兴趣的:(清理.git文件)