Last active
August 29, 2015 14:20
-
-
Save leedm777/bbd9f08390c324c79283 to your computer and use it in GitHub Desktop.
Erases a file from the history of the current branch
This file contains hidden or 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/sh | |
# | |
# Removes a file from git history of the current branch | |
# | |
PROGNAME=$(basename $0) | |
REMOVE=$1 | |
REPO_NAME=$(basename $(pwd)) | |
if test -z ${REMOVE}; then | |
echo "usage: ${PROGNAME} [file-to-erase-from-history]" >&2 | |
exit 1 | |
fi | |
if ! test -d .git; then | |
echo "${PROGNAME}: Must run from git repo" >&2 | |
exit 1 | |
fi | |
set -ex | |
git filter-branch --force --index-filter \ | |
"git rm -r --cached --ignore-unmatch ${REMOVE}" \ | |
--prune-empty | |
# | |
# Push to a fresh bare repo to get a sense of how small it is now | |
# | |
rm -rf /tmp/${REPO_NAME} | |
git init --bare /tmp/${REPO_NAME} | |
git push /tmp/${REPO_NAME} HEAD:master | |
du -sh /tmp/${REPO_NAME} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment