Last active
January 16, 2018 16:54
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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