Usage at your own risk. Read the official documentation for more info.
I wanted to delete two folders from a repositories history. Finally successful for me was the BFG Repo-Cleaner tool. I used it on MacOS like so:
First I downloaded the tool and placed it inside my repository's root. Then ran this command to repack the repository:
After that, I picked the command to delete all folders named "impressum":
java -jar bfg-1.14.0.jar --delete-folders "impressum"
It ran successfully and asked me to run this command:
git reflog expire --expire=now --all && git gc --prune=now --aggressive
Then, upload the changes to GitHub:
git add . git commit -m "delete folder from history" git push --force
The forced push may be necessary because Git will not just let you overwrite the repositories history. But since that's what we want, --force ignores any warning and pushes the changed history to GitHub.
To check the Git repositories history for a string that should be deleted, this command may be used:
git log -S password
You can exchange "password" with any string that should not be included in the repo anymore. If no string is found, there will be nothing displayed in the terminal. If there is something found, you get information about the commit where the data is included.
I'm still figuring this out, but if there is a conflict when pulling the changes to another machine, an easy way would be to just clone the repository again.
Tool download from here: https://rtyley.github.io/bfg-repo-cleaner/