Skip to content

Instantly share code, notes, and snippets.

@suderman
Created April 5, 2013 05:38
Show Gist options
  • Save suderman/5316899 to your computer and use it in GitHub Desktop.
Save suderman/5316899 to your computer and use it in GitHub Desktop.
Remove files from git history
# FIND BIG FILES:
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 -n100 | \
while read hash type size; do
echo -n "-e s/$hash/$size/p ";
done) | \
sort -n -k1
# REMOVE BIG FILES
git filter-branch -f --index-filter \
'git rm --force --cached --ignore-unmatch UNWANTED-DIR/UNWANTED-FILE.PSD' \
-- --all
rm -Rf .git/refs/original && \
git reflog expire --expire=now --all && \
git gc --aggressive && \
git prune
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment