Skip to content

Instantly share code, notes, and snippets.

@JosephGaiser
Created August 18, 2020 18:14
Show Gist options
  • Save JosephGaiser/216f919ab685d4258c686dbaa77667c0 to your computer and use it in GitHub Desktop.
Save JosephGaiser/216f919ab685d4258c686dbaa77667c0 to your computer and use it in GitHub Desktop.
Rewrite history to remove any sensative data without deleteing files
# Sync with the remote master
git pull
# Force your clone to look like HEAD
git reset --hard
# AGAIN, A WARNING: This can really break stuff!
# Run your filter branch command, replacing all instances of "password" with "your_password"
# The example looks for Ruby files ("*.rb"), you can change this to match your needs
git filter-branch --tree-filter 'git ls-files -z "*.rb" |xargs -0 perl -p -i -e "s#(password)#your_password#g"' -- --all
# Overwrite your master with local changes
git push origin master --force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment