在做項目提交是,不小心將敏感信息提交到代碼倉庫,並且已發佈到公共倉庫中,後續操作雖然將敏感信息進行替換後,提交的歷史記錄中依然可以查詢到敏感信息,如何將提交信息清除,成爲困擾自己的問題。
經過以下步驟後,你將獲得一個清爽的倉庫
- 切換到新的分支
git checkout --orphan latest_branch
- 緩存所有文件(處理 .gitignore 中聲明排除的)
git add -A
- 提交跟蹤過的文件(Commit the changes)
git commit -am "commit message"
- 刪除
master
分支(Delete the master branch)
git branch -D master
- 重命名當前分支爲
master
(Rename the current branch to master)
git branch -m master
- 提交到遠程
master
分支(Finally, force update your repository)
git push -f origin master