使用git filter-repo删除已提交到git中的敏感信息,api key,配置文件等

使用git filter-repo删除已提交到git中的敏感信息,api key,配置文件等 使用git filter-repo删除已提交到git中的敏感信息api key配置文件等前提条件Python 3.5git 2.22.0通过 pip 安装pip install git-filter-repo注意事项官方推荐在fresh clone上修改即clone一份远程的再做修改操作后所有协作者必须重新 clone因为历史被重写SHA 全部改变不能直接 pull安装pypthon在官网下载安装时注意勾选☑️Add python.exe to PATH最重要默认不勾验证是否安装成功python--versionpip--versionpip是 Python 的包管理工具用来安装第三方库。类比ava 的Maven/GradleNode.js 的npm安装git filter-repopipinstallgit-filter-repo删除api key这里以一个openssl生成的密钥为例在spring项目中我们会使用application.yml来配置密钥有时会不小心把本地开发的密钥push上去password3afRJQRWzdai5JRSYx3SzZTMCs0szypM4vT2/qDE6Y我们可以将此密钥替换为YOUR_PASSWORD在项目中新建一个replacements.txt文件里面的内容为3afRJQRWzdai5JRSYx3SzZTMCs0szypM4vT2/qDE6YYOUR_PASSWORD执行以下git命令用filter之后要重新添加远程仓库后再pushgitfilter-repo --replace-text replacements.txtgitremoteaddorigin 你的仓库地址gitpush origin--force--all删除敏感文件执行以下git命令gitfilter-repo--path文件路径 --invert-paths--forcegitremoteaddorigin 你的仓库地址gitpush origin--force--allrt-paths --forcegit remote add origin 你的仓库地址git push origin --force --all