如何从github历史记录中的文件中删除敏感数据
我正在使用共享的github存储库在项目上进行协作.因为我是个白痴,所以我提交并推送了一个脚本文件,其中包含不想共享的密码(是的,我可以更改密码,但是无论如何我都希望将其删除!).
I am using a shared github repository to collaborate on a project. Because i am an idiot, I committed and pushed a script file containing a password which I don't want to share (Yes, i can change the password, but I would like to remove it anyway!).
是否有任何方法可以从github的历史中还原提交,在本地删除密码,然后重新提交并推送更新的文件?我不想完全删除文件,并且我不希望丢失github上的提交历史记录.
Is there any way to revert the commits from github's history, remove the password locally and then recommit and push the updated files? I do not want to remove the file completely, and I would rather not lose the commit history on github.
(此问题 如何从git中完全删除文件存储库? 显示了如何删除敏感文件,但没有显示如何从文件中删除敏感数据,因此这不是重复的内容
(This question How can I completely remove a file from a git repository? shows how to remove a sensitive file, but not how to edit sensitive data from a file, so this is not a duplicate)
我建议使用新的替换了BFG和git filter-branch
.
I would recommend to use the new git filter-repo
, which replaces BFG and git filter-branch
.
注意:如果在运行上述命令时收到以下错误消息:
Note: if you get the following error message when running the above-mentioned commands:
Error: need a version of `git` whose `diff-tree` command has the `--combined-all-paths` option`
这意味着您必须更新git
.
it means you have to update git
.
首先:执行一份本地存储库副本(一个新克隆)
First: do that one copy of your local repo (a new clone)