Created
December 4, 2013 08:46
-
-
Save svenvarkel/7784318 to your computer and use it in GitHub Desktop.
This script helps to remove specified files or folders from the whole GIT repository history
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 | |
# 1. list git branches | |
# 2. iterate thru branches | |
# 3. for each branch do git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch FILENAME" HEAD | |
filepath=$1 | |
remove_large_files(){ | |
for branch in $(git branch) | |
do | |
echo "Removing ${filepath} from ${branch}" | |
git filter-branch -f --index-filter "git rm -rf --cached --ignore-unmatch ${filepath}" $branch | |
done | |
rm -rf .git/refs/original/ && git reflog expire --all && git gc --aggressive --prune | |
} | |
case "$1" in | |
"") | |
echo "Please specify file path to be removed" | |
echo "Example: git-remove-large-files.sh htdocs/large_dump.sql" | |
exit 1 | |
;; | |
*) | |
remove_large_files | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment