背景
公开repo的时候会担心曾经有不小心commit的密码能在commit历史里被翻出来。所以可以用BFG Repo-Cleaner by rtyley把历史记录里的密码替换成REMOVED。
steps
- download bfg.jar from repo1.maven.org/maven2/com/…
- write your passwords in passwords.txt
username1
password1
username2
password2
- replace history and push
git clone --mirror git://xxx.com/xxx.git
java -jar bfg.jar --replace-text passwords.txt xxx.git
cd xxx.git
git reflog expire --expire=now --all && git gc --prune=now --aggressive
git push --force
如果这个push成功了就大功告成了。
失败的话可能是[remote rejected] refs/pull/xxx
报错,这是因为git clone --mirror
会把pull request 也clone下来,而github目前不能直接修改pr,需要联系support人员才可能实现,所以push失败,参考Delete a closed pull request from GitHub - Stack Overflow。如果只是git clone
,不用mirror,可以修改main分支的密码成功,但pr history密码还在。如果想彻底消除影响就还是得新建一个repo或者改密码。