Skip to content

Instantly share code, notes, and snippets.

@ANemcov
Forked from skhatri/git_big_files.sh
Created December 27, 2015 18:50
Show Gist options
  • Save ANemcov/0c12b2b3a67fd78d1cda to your computer and use it in GitHub Desktop.
Save ANemcov/0c12b2b3a67fd78d1cda to your computer and use it in GitHub Desktop.
remove big files from git history
#list top 10 big files
index_file=$(ls .git/objects/pack/pack-*.idx)
for x in $(git verify-pack -v $index_file| sort -k 3 -n | tail -10); do
git rev-list --objects --all | grep $x
done
#remove all war
git filter-branch -f --index-filter 'git rm -rf --cached --ignore-unmatch *.war' -- --all
#pack all
git pack-refs --all --prune
#expire old reflogs
git reflog expire --expire-unreachable=now --all
#pack unpacked files
git repack -A -d
#git clean up
git gc --aggressive --prune=now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment