【Git】如何清除 Git 倉庫的所有提交記錄

在做項目提交是,不小心將敏感信息提交到代碼倉庫,並且已發佈到公共倉庫中,後續操作雖然將敏感信息進行替換後,提交的歷史記錄中依然可以查詢到敏感信息,如何將提交信息清除,成爲困擾自己的問題。

經過以下步驟後,你將獲得一個清爽的倉庫

  1. 切換到新的分支
git checkout --orphan latest_branch
  1. 緩存所有文件(處理 .gitignore 中聲明排除的)
git add -A
  1. 提交跟蹤過的文件(Commit the changes)
git commit -am "commit message"
  1. 刪除 master 分支(Delete the master branch)
git branch -D master
  1. 重命名當前分支爲 master(Rename the current branch to master)
git branch -m master
  1. 提交到遠程 master 分支(Finally, force update your repository)
git push -f origin master
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章