如何永久删除git仓库中敏感文件的提交记录

本文提供了一步一步的操作指南,详细解释了如何使用Git命令永久删除仓库中包含敏感文件的提交记录,确保数据安全。


如何永久删除git仓库中敏感文件的提交记录。



官方资料:

https://help.github.com/articles/remove-sensitive-data/

http://git-scm.com/book/zh/v2/Git-%E5%B7%A5%E5%85%B7-%E9%87%8D%E5%86%99%E5%8E%86%E5%8F%B2

http://stackoverflow.com/questions/2004024/how-to-permanently-delete-a-file-stored-in-git



下载git2.2.1并将git添加到环境变量中

># wget https://github.com/git/git/archive/v2.2.1.tar.gz
># tar zxvf v2.2.1.tar.gz
># cd git-2.2.1
># make configure
># ./configure --prefix=/usr/local/git --with-iconv=/usr/local/libiconv
># make all doc
># make install install-doc install-html
># echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc
># source /etc/bashrc

查看版本号

># git --version
>git version 2.2.1


步骤整理:

假定需要删除的文件为:src/main/resources/passowrd.txtx


git filter-branch --index-filter 'git rm -r --cached --ignore-unmatch src/main/resources/passowrd.txtx' HEAD

git reflog expire --expire=now --all  
git gc --prune=now  
git gc --aggressive --prune=now


git push --all --force


命令执行成功后,查看远程资源库的提交记录(包括需要删除文件的提交记录),查看这个更新内容这个文件已经被删除。








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值