Skip to content

Instantly share code, notes, and snippets.

@madhikarma
Created October 16, 2019 05:11
Show Gist options
  • Save madhikarma/ca836d5ad78f1a6bb15be8e692a855f0 to your computer and use it in GitHub Desktop.
Save madhikarma/ca836d5ad78f1a6bb15be8e692a855f0 to your computer and use it in GitHub Desktop.
Git remove files/text from history snippet
# Remove folder (tested)
git filter-branch --tree-filter 'rm -rf FOLDER_PATH' --prune-empty HEAD
# Remove file (not tested)
git filter-branch --force --index-filter \
"git rm --cached --ignore-unmatch FILE_PATH" \
--prune-empty --tag-name-filter cat -- --all
# Remove text (not tested)
git filter-branch --tree-filter "find . -type f -exec sed -i -e 's/ORIGINAL_PASSWORD/NEW_PASSWORD/g' {} \;"
# Links
# https://blog.ostermiller.org/git-remove-from-history
# https://davidverhasselt.com/git-how-to-remove-your-password-from-a-repository/
# https://help.github.com/en/articles/removing-sensitive-data-from-a-repository
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment