git的过滤分支删除字符串,但如果字符串包含$'\\和其它字符 [英] git-filter-branch to remove strings, but where strings contain $ ' \ and other characters

查看:1161
本文介绍了git的过滤分支删除字符串,但如果字符串包含$'\\和其它字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图改写历史,使用:

I'm trying to rewrite history, using:

git的过滤分支--tree过滤器'git的LS-文件-z* .PHP| xargs的-0的perl -p -i -eS#(PASSWORD1 |密码2 | PASSWORD3 )##XXXXXXXXXXX G' - --all

作为rel=\"nofollow\">本教程

as described in this tutorial.

但是,密码字符串我有包含各种非A-Z的字符,例如$'和\\,而不是漂亮的简单的'在上面的例子中PASSWORD1类型的字符串。

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.

推荐答案

您可以使用的的更友好的替代格式,如果您使用该BFG 而非 git的过滤分支。创建一个 password.txt的文件,每行一个口令是这样的:

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 a passwords.txt file, with one password per line like this:

PASSWORD1==>xXxXx      # Replace literal string 'PASSWORD1' with 'xXxXx'
ezxcdf\fr$sdd%==>xXxXx # ...all text is matched as a *literal* string by default

然后使用此命令运行BFG

$ java -jar bfg.jar -fi '*.php' --replace-text passwords.txt  my-repo.git

您整个存储库的历史将被扫描,并且所有的.php 文件(1MB大小的下)将有换人执行:任何匹配的字符串(不在您的最新的的提交)将被替换。

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.

注意解析BFG的唯一位在这里用替换的文件确实是分裂的 ==> '字符串 - 这很可能的是不是的在您的密码 - 而且所有文字间$ p $默认PTED字面上

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.

如果你想更加简洁,你可以删除 ==> 和之后的自带每行的一切(即只是有密码的)和BFG将替换字符串 *** *** REMOVED 默认情况下。

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.

该BFG通常快几百倍比运行 git的过滤分支上一个大的回购和选项都围绕这两个常见的用例定制的:

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:


  • 删除疯狂大文件

  • 删除密码,证书&安培;其他的私有数据

  • Removing Crazy Big Files
  • Removing Passwords, Credentials & other Private data

全面披露:我是BFG回购清洁的作者

这篇关于git的过滤分支删除字符串,但如果字符串包含$'\\和其它字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆