Skip to content

Instantly share code, notes, and snippets.

@geraudmathe
Last active January 16, 2018 16:54
Show Gist options
  • Save geraudmathe/547686d9354c3c267153d1ee7c49a028 to your computer and use it in GitHub Desktop.
Save geraudmathe/547686d9354c3c267153d1ee7c49a028 to your computer and use it in GitHub Desktop.
This is useful to retrieve big files from git history and delete them from all history
#the command below will look at ALL objects in history and show you the biggest ones
git rev-list --all --objects |
sed -n $(git rev-list --objects --all | cut -f1 -d' ' | git cat-file --batch-check | grep blob | sort -n -k 3 | tail -n40 | while read hash type size; do echo -n "-e s/$hash/$size/p "; done) | sort -n -k1
#the command below will remove all reference for a given file
git filter-branch --force --index-filter 'git rm --cached -r --ignore-unmatch REPLACE_WITH_PATH' --prune-empty --tag-name-filter cat -- --all
# remove old referenes
rm -rf .git/refs/original/
# remove old referenes
git reflog expire --expire=now --all
# recreate referenes
git gc --prune=now
git gc --aggressive --prune=now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment