Skip to content

Instantly share code, notes, and snippets.

@chengsoonong
Created May 8, 2015 02:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chengsoonong/cabe9ed11881346330b0 to your computer and use it in GitHub Desktop.
Save chengsoonong/cabe9ed11881346330b0 to your computer and use it in GitHub Desktop.
Delete a file, and destroy its history in git.
#!/bin/bash
# This script removes a file from the git repository and destroys all its history.
#
# Based on https://help.github.com/articles/remove-sensitive-data/
#
# To do a dry run, add a -n to the git rm command. I.e.
# "git rm -n --cached --ignore-unmatch $1"
printf "Really destroy $1 ? y/[n] "
read -n 1 destroy
if [ "$destroy" == "y" ]; then
printf "\nDestroying $1\n"
git filter-branch --force --index-filter \
"git rm -r --cached --ignore-unmatch $1" \
--prune-empty --tag-name-filter cat -- --all
else
printf "\nDid not destroy $1\n"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment