Skip to content

Instantly share code, notes, and snippets.

@edwardsmatt
Last active August 29, 2015 14:11
Show Gist options
  • Save edwardsmatt/cce80da862ac10e1dc4f to your computer and use it in GitHub Desktop.
Save edwardsmatt/cce80da862ac10e1dc4f to your computer and use it in GitHub Desktop.
Remove file from git history and tags.
Based on this -https://gist.github.com/shennyg/1047737- modified to use the instructions from: https://help.github.com/articles/remove-sensitive-data/
* This will overwrite your existing tags.
#!/bin/bash
set -o errexit
if [ $# -eq 0 ]; then
exit 0
fi
if [ ! -d .git ]; then
echo "Error: please go to the root of the git repository and try running this again"
exit 1
fi
files=$@
git filter-branch --force --index-filter "git rm -rf --cached --ignore-unmatch $files" --prune-empty --tag-name-filter cat -- --all
git for-each-ref --format='delete %(refname)' refs/original | git update-ref --stdin && git reflog expire --expire=now --all && git gc --aggressive --prune=now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment