如何从github历史记录中的文件中删除敏感数据

问题描述 投票:0回答:1

我正在使用共享的github存储库在项目上进行协作。因为我是个白痴,所以我提交并推送了一个脚本文件,其中包含不想共享的密码(是的,我可以更改密码,但无论如何我都希望将其删除!)。

是否有任何方法可以从github的历史中还原提交,在本地删除密码,然后重新提交并推送更新的文件?我不想完全删除文件,并且我不希望丢失github上的提交历史记录。

(这个问题How can I completely remove a file from a git repository?显示了如何删除敏感文件,但没有显示如何从文件中删除敏感数据,因此这不是重复的内容]

git github revert
1个回答
0
投票

使用BFG:https://rtyley.github.io/bfg-repo-cleaner/

要删除文件:

$ bfg --delete-files <file to remove>  my-repo.git

您还可以使用此工具删除密码和蚂蚁敏感数据。

准备一个包含您要替换的内容的替换文件,并使用BFG清除它。

bfg --replace-text passwords.txt  my-repo.git

# Example of the passwords.txt file: 
string1                   # Replace string ***REMOVED***' (default text)
string2==>replacementText # replace with 'replacementText' instead
string3=>                 # replace with the empty string
© www.soinside.com 2019 - 2024. All rights reserved.