I'm trying to rewrite history, using:
git filter-branch --tree-filter 'git ls-files -z "*.php" |xargs -0 perl -p -i -e "s#(PASSWORD1|PASSWORD2|PASSWORD3)#xXxXxXxXxXx#g"' -- --all
as described in this tutorial.
However, the password strings I have contain all kinds of non- A-Z characters, e.g. $ ' and \, rather than being nice simple 'PASSWORD1' type strings in the example above.
Can someone explain what escaping I need? I've not been able to find this anywhere, and I've been battling with this for hours.
try the BFG instead of git filter-branch...
You can use a much more friendly substitution format if you use The BFG rather than
git-filter-branch
. Create apasswords.txt
file, with one password per line like this:Then run the BFG with this command:
Your entire repository history will be scanned, and all
.php
files (under 1MB in size) will have the substitutions performed: any matching string (that isn't in your latest commit) will be replaced....no escaping needed
Note that the only bit of parsing the BFG does with here with the substitution file is to split on the '
==>
' string - which probably isn't in your passwords - and all text is interpreted literally by default.If you want to be even more concise, you can drop the '
==>
' and everything that comes after it on each line (ie, just have a file of passwords) and The BFG will replace each password with the string '***REMOVED***
' by default.The BFG is typically hundreds of times faster than running
git-filter-branch
on a big repo and the options are tailored around these two common use-cases:Full disclosure: I'm the author of the BFG Repo-Cleaner.