git目录中可能因为失误或者其他原因上传了敏感文件,需要从多个分支中删除敏感文件及其历史记录
流程
- 使用filter-branch命令移除本地所有分支的敏感文件历史记录
- 参数将会强制git处理而不是回退,所有分支及标签历史上的指定文件
git filter-branch --force --index-filter
'git rm --cached --ignore-unmatch [敏感文件]'
--prune-empty --tag-name-filter cat -- --all
- 将敏感文件加入gitignore
echo "[敏感文件的根目录路径]" >> .gitignore
- 强制更新远程仓库
git push origin --force --all