-
-
Save atdt/2976600 to your computer and use it in GitHub Desktop.
Permanently remove crap from a git repo.
This file contains 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
#!/bin/bash | |
### Rewrite history (all commits in all branches) without the files that match the pattern | |
DELETE_PAT="$1" | |
git filter-branch --tree-filter "rm -rf $1" --prune-empty --tag-name-filter cat -- --all | |
### filter-branch saves the original history to refs/original | |
### because we aim to reclaim space, we need to remove it and then gc the refs | |
git for-each-ref --format="%(refname)" refs/original/| xargs -n 1 git update-ref -d | |
git reflog expire --expire=now --all | |
git gc --prune=now | |
### before removing any old remotes, you'll want to check out the branches | |
for b in $(git branch -r | grep -v -e '->'); do | |
git checkout $(cut -d/ -f2) | |
done | |
### remove whatever old remotes are scary | |
git remote rm origin | |
### finally, you'll want to push this repo with modified history someplace new | |
git remote add origin NEW_REMOTE | |
git push origin --all |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment