Skip to content

Instantly share code, notes, and snippets.

@berikv
Created February 7, 2012 19:35
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 berikv/1761420 to your computer and use it in GitHub Desktop.
Save berikv/1761420 to your computer and use it in GitHub Desktop.
Remove files from git history
toRemove='someDirectory/* bigFile.txt'
# Remove every file that matches $toRemove
git filter-branch -f --index-filter "git rm -rf --cached --ignore-unmatch $toRemove" --prune-empty -- --all
# Rebuild the history cache (does not seem to remove big file from the git caches... maybe not required)
rm -rf .git/refs/original/ && git reflog expire --all && git gc --aggressive --prune
# Make a clean clone
cd ..
git clone --no-hardlinks ${REPO} ${REPO}-reduced
# Start using the new clone, remove the old repo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment