Loading... > 最近往github push代码时不小心将token等敏感数据一起给提交到了仓库,如果是单次的话可以选择回退到上一次提交,或者还未push到仓库的情况下可以选择`git commit --amend`,但是我后续很多次commits都未对这个文件进行脱敏处理,这种情况就会比较麻烦。 1.遍历所有的commit,删除指定文件,重写历史commit ``` git filter-branch --force --index-filter "git rm --cached --ignore-unmatch <file path>" --prune-empty --tag-name-filter cat -- --all ``` 2.本地记录覆盖到Github (所有branch以及所有tags) ``` git push origin --force --all git push origin --force --tags ``` 3.强制解除对本地存储库中的所有对象的引用和垃圾收集 ``` git for-each-ref --format='delete %(refname)' refs/original | git update-ref --stdin git reflog expire --expire=now --all git gc --prune=now ``` 最后修改:2020 年 12 月 24 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 1 如果觉得我的文章对你有用,请随意赞赏
2 条评论
我也是好几次忘记脱敏