git-从git历史记录中删除关键数据

时间:2019-09-11 12:52:35

标签: git security

我从我们公司的一个项目中克隆了一个存储库,并注意到git中存储了关键信息,例如数据库密码,盐键等。

我有责任以某种方式解决这个问题。我唯一的想法是创建一个新的存储库并正确执行,但是随后我们松开了整个git历史记录,这是唯一的解决方案吗?

示例文件结构:

app/Main.php
db/connect.php  <-- critical passwords inside

文件db / connect.php在第一次提交中。 一种方法是将文件添加到.gitignore中,然后更改数据库密码,但不适用于DB Saltkey ofc。

1 个答案:

答案 0 :(得分:1)

您可以使用git内置的git-filter-branch,更多信息请参考this answer

git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch filepattern' --prune-empty --tag-name-filter cat -- --all
相关问题