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