Skip to content

Instantly share code, notes, and snippets.

@ashugupt
Last active August 28, 2017 10:41
Show Gist options
  • Save ashugupt/1d46fac48446f7c0408f9c8deab22c84 to your computer and use it in GitHub Desktop.
Save ashugupt/1d46fac48446f7c0408f9c8deab22c84 to your computer and use it in GitHub Desktop.
Cleanup a git repository of unwanted files/history
# List all large blobs in a git repository sorted by blob size in descending order.
git rev-list --objects master | git cat-file --batch-check='%(objectsize) %(objecttype) %(objectname) %(rest)' | sort -k1,1 -rn > ~/Desktop/abc.txt
# Rewrite history removing history of a file
git filter-branch --force --index-filter \
'git rm --cached --ignore-unmatch <path/to/unwanted/file>' \
--prune-empty --tag-name-filter cat -- --all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment