git-filter-branch to remove strings, but where strings contain $ ' \ and other characters

后端 未结 4 2080
渐次进展
渐次进展 2021-01-07 09:12

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)#

4条回答
  •  半阙折子戏
    2021-01-07 09:39

    Build it from the inside out. Say the password is

    a$b'c\d
    

    The regex pattern would be

    a\$b'c\\d
    

    One possibility for the perl command would be

    perl -i -pe's/a\$b'\''c\\d/.../g'
    

    (Note how each ' was replaced with '\''.)

    Now you need to include that in single quotes, so you repeat the process.

    ... '... perl -i -pe'\''s/a\$b'\''\'\'''\''c\\d/.../g'\''' ...
    

提交回复
热议问题