I am cleaning a local git repo with a lot of large tarballs in the history. I did the following steps:
- List the all the tarball files in the repo
FILE_LIST=`git rev-list master | while read rev; do git ls-tree -lr $rev | cut -c54- | sed 's/^ +//g;'; done | grep <tarball name> | awk '{print $2}' | sort | uniq | tr '\n' ' '`
- Mark them for deletion
git filter-branch --tag-name-filter cat --index-filter "git rm -r --cached --ignore-unmatch $FILE_LIST" --prune-empty -f -- --all
- Garbage collection
rm -rf .git/refs/original/ && git reflog expire --expire=now --all && git gc --aggressive --prune=now
- Push
git push origin --force --all && git push origin --force --tags
By doing this I reduced the size of the local repo significantly. However, when I got a clean clone from the origin after the above steps, the size of the cloned repo is not reduced, but those large tarballs are gone by verifying
FILE_LIST=`git rev-list master | while read rev; do git ls-tree -lr $rev | cut -c54- | sed 's/^ +//g;'; done | grep <tarball name> | awk '{print $2}' | sort | uniq | tr '\n' ' '`
I did the garbage collection step again in the cloned repo, the size was not reduced.
Anyone know how I can reduce the repo size on the original server? Thanks in advance.