当前位置:   article > 正文

BFG 删除Git提交历史记录中的敏感信息_bfg-repo-cleaner 删除敏感信息

bfg-repo-cleaner 删除敏感信息

日常提交代码的时候可能遇到的一个问题就是,不小心将一些数据库配置或者密钥文件提交到了线上,后面就算删除掉提交的文件,但是相关信息还是可以在历史版本中看到,下面介绍一下使用BFG Repo-Cleaner 来处理这种情况

BFG Repo-Cleaner

Removes large or troublesome blobs like git-filter-branch does, but faster. And written in Scala
BFG可以用来移除大文件或者处理我们想从 git history中的内容,就像GIt提供的git-filter-branch命令那样,不过比他更快。

步骤

1. 安装BFG

wget http://repo1.maven.org/maven2/com/madgag/bfg/1.12.16/bfg-1.12.16.jar

BFG需要在java环境执行
The Java Runtime Environment (Java 8 or above - BFG v1.12.16 was the last version to support Java 7)

2. clone一份镜像数据

bfg提供的破坏性操作一旦执行,后面就没办法找回之前的状态,所以为了以防万一,先备份

$ git clone --mirror git://example.com/some-big-repo.git
  • 1

3. 替换敏感数据

$ java -jar bfg.jar --replace-text replacements.txt my-repo.git
  • 1
  • bfg.jar:下的什么版本这里就改成对应版本的bfg.jar,前文中使用wget下载了bfg-1.12.16.jar
  • replacements.txt: 中填写需要替换的字段,可以使用正则匹配,默认使***REMOVED***代替原内容
  • my-repo.git:本地git项目路径

Replace with ‘REMOVED’ (default)

PASSWORD1 
# replace with 'examplePass' instead
PASSWORD2==>examplePass
#replace with the empty string
PASSWORD3==> 
  • 1
  • 2
  • 3
  • 4
  • 5

4. 删除缓存数据

$ git reflog expire --expire=now --all
$ git gc --prune=now
  • 1
  • 2

5. 提交本地修改到仓库

$ git push origin --force --all
$ git push origin --force --tags
  • 1
  • 2
  • –all参数是作用于所有分支上

6. 更新其他的clone

如果其他服务器或者电脑上clone了该仓库的代码,简单使用git pull是无法更新前文中的修改的
这里用到的命令是:

$ git fetch origin 
$ git reset --hard origin/master
  • 1
  • 2

然后同样用一下命令删除一下缓存信息

$ git reflog expire --expire=now --all
$ git gc --prune=now
  • 1
  • 2
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/438546
推荐阅读
相关标签
  

闽ICP备14008679号