git仓库删除全部提交历史记录,成为一个干净的新仓库

把旧项目提交到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 branch)
git branch -D master

5.重命名当前分支为master(Rename the current branch to master)code

git branch -m master

6.提交到远程master分支 (Finally, force update your repository)it

git push -f origin master
相关文章
相关标签/搜索