This is how to remove an expression from all files in a project versioned with git so that it doesn’t appear anywhere, including in the history, previous commits, and so on.
Note that making changes in the git history is always risky and should only be done with clear understanding of what you’re doing, or on non-critical projects. I encourage you to try it on a dummy project first if you’re not confident.
There are several tools (git filter-branch, BFG cleaner, git-filter-repo)
I used git-filter-repo on Windows.
Make sure Python is installed on your machine and added to your $PATH.
Make sure there are no uncommitted changes in your project.
Download the git-filter-repo script and place it in your project (don’t add it to files to commit, add it to git-exclude).
Create a texte file for expressions to remove. Don’t commit it (add it to git-exclude). You can specify a replacement expression with “==>” or let it replace with a default expression.
expression_to_remove1==>replacement_expression
expression_to_remove2
Run this command in your project:
py git-filter-repo --replace-text sensitive.txt --force
If you get an error about not having a fresh clone, delete the project from your computer and clone it from the source before repeating the whole process.
If your project is not versioned with git, you can just use the Replace function from your IDE!
If your project is versioned with git but not yet pushed on a remote git server, you might find it easier to make your replacement locally and squash all commits for the targeted files (depending on how much you want to keep from your commit history).
