Earlier this month I was promoted to a new position and inherited a website. I loaded the site into a git repository and started working, but about 50 commits later I realized that there were dozens of .txt files scattered throughout the site containing user names and email addresses. Because I've already deployed a complete re-write of the site, I'm not worried about any collateral damage and want to delete every .txt file in every commit of the repository. I know individual files can be removed with git filter-branch
, but my attempt to scale it didn't seem to do anything.
git filter-branch --force --index-filter \
"find . -type f | grep .txt | xargs -I {} git rm --cached --ignore-unmatch {}" \
--prune-empty --tag-name-filter cat -- --all
What is the best way to delete every .txt file in the history of a git repository? Can it be done without having to rewrite the entire history for each file?