1、运行count-objects 查看空间使用
$ git count-objects -v
结果:
count: 2399
size: 20464
in-pack: 590641
packs: 47
size-pack: 4732867
prune-packable: 518
garbage: 0
size-garbage: 0
size-pack 是以kb为单位表示的。
2、找到大文件
$ git verify-pack -v .git/objects/pack/pack-*.idx | sort -k 3 -n | tail -4
对输出的第三列信息即文件大小进行排序,获取最大的四个文件。
结果
528d2bdc6bfb7eefd913f162c05a4e4dd23e4506 blob 142832910 142100132 219295613
528d2bdc6bfb7eefd913f162c05a4e4dd23e4506 blob 142832910 142100132 883203532
8aa267f83d48a4ab5c3076fc56ca8c0645c9a204 blob 182385951 180958502 1251898955
8aa267f83d48a4ab5c3076fc56ca8c0645c9a204 blob 182385951 180958502 175922994
然后通过下面的命令找到文件的名称
$ git rev-list --objects --all | grep 8aa267f83d48a4ab5c3076fc56ca8c0645c9a204
执行结果
8aa267f83d48a4ab5c3076fc56ca8c0645c9a204 scripts/deploy/uxmpp/uxdb-install.tar.gz
2.移除git与大文件的引用关系
通过filter-branch遍历git,并移除与Pods文件夹中文件的引用关系
$ git filter-branch --index-filter ‘git rm -r --cached --ignore-unmatch scripts/deploy/uxmpp/uxdb-install.tar.gz’
现在历史记录中已经不包含对于那些大文件的引用了.
3.转移仓库
$ git clone file:///path/to/repository.
Note that the file:// makes a world of difference when cloning a local repository - only the referenced objects are copied across, not the whole directory structure.
译:注意当复制一个本地仓库的时候,file://让一切变得大不相同.–只有拥有引用关系的文件会复制过去,而不是所有的文件结构!
这样的话我们就可以通过这个方法丢掉那些大文件啦,于此同时保留的剩余的文件以及引用关系.
转移仓库部分具体参见:
http://stackoverflow.com/questions/1029969/why-is-my-git-repository-so-big/1036595#