如何永久刪除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


命令執行成功後,查看遠程資源庫的提交記錄(包括需要刪除文件的提交記錄),查看這個更新內容這個文件已經被刪除。








發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章