Skip to content

Instantly share code, notes, and snippets.

@kavu
Last active December 14, 2015 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kavu/5107579 to your computer and use it in GitHub Desktop.
Save kavu/5107579 to your computer and use it in GitHub Desktop.
This is how you can delete some HUGE dir in your repo's history. Warning! Make a backup and don't try it, if you don't understand what are you doing!
# Let's figure out what we have in the beggning
git fsck --full --strict --unreachable
git count-objects -v
# Filter ALL branches deleteing `db/seeds_assets`
git filter-branch -f --tree-filter 'rm -rf db/seeds_assets' -- --all
# Remove original reflogs
rm -rf .git/refs/original/
# Expire old and unuses reflogs
git reflog expire --expire=now --expire-unreachable=now --all --rewrite
# Compress
git gc --aggressive --prune=now
# Let's check again
git fsck --full --strict --unreachable
git count-objects -v
# Push all branches to the origin
git push origin --all --force -u
## Additional links
# http://git-scm.com/book/en/Git-Internals-Maintenance-and-Data-Recovery
# http://dalibornasevic.com/posts/2-permanently-remove-files-and-folders-from-a-git-repository
# https://www.kernel.org/pub/software/scm/git/docs/git-filter-branch.html#_checklist_for_shrinking_a_repository
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment