Created
September 7, 2014 03:56
-
-
Save alexanderscott/772c1c5802c5b3204afb to your computer and use it in GitHub Desktop.
remove file from git history, prune & garbage collect, push removal to origin
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 | |
# Get filename from cmd-line arg | |
filename=$1 | |
# Fetch all remote branches locally and setup tracking | |
for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master`; do | |
git branch --track ${branch##*/} $branch | |
done | |
# Remove file from git history & garbage collect | |
git filter-branch --tag-name-filter cat --index-filter 'git rm -r --cached --ignore-unmatch $filename' --prune-empty -f -- --all | |
rm -rf .git/refs/original/ | |
git reflog expire --expire=now --all | |
git gc --prune=now | |
git gc --aggressive --prune=now | |
# Push updates | |
git push origin --force --all | |
git push origin --force --tags |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment