Created
June 8, 2014 15:51
-
-
Save dekarrin/f795427e183fc8976a37 to your computer and use it in GitHub Desktop.
Totally remove file from 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 | |
TEMP_DIR=".git_annhilate_temp" | |
if [[ $3 == "" ]] | |
then | |
echo Usage: $0 ssh-repo-url branch file-to-delete | |
else | |
F=0 #failure check | |
REPO_URL=$1 | |
BRANCH=$2 | |
DELETE_FILE=$3 | |
git clone $REPO_URL $TEMP_DIR || let "F |= 1" | |
cd $TEMP_DIR | |
if [[ $BRANCH == "master" ]] | |
then | |
git checkout $BRANCH || let "F |= 1" | |
fi | |
git filter-branch --index-filter "git rm --cached --ignore-unmatch $DELETE_FILE" --prune-empty --tag-name-filter cat -- --all || let "F |= 1" | |
git push --tags --force origin $BRANCH || let "F |= 1" | |
cd .. | |
rm -rf $TEMP_DIR | |
if [[ $F == 0 ]] | |
then | |
echo "" | |
echo "File removed from git history." | |
echo "WARNING: All clones/forks based on origin must be recloned/rebased or merge conflicts may occur!" | |
fi | |
fi | |
TEMP_DIR="" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment