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

场景

把旧项目提交到Git上,可是会有一些历史记录,这些历史记录中可能会有项目密码等敏感信息。如何删除这些历史记录,造成一个全新的仓库,而且保持代码不变呢?git

操做

Checkoutcode

git checkout --orphan latest_branch

Add all the filesit

git add -A

Commit the changesast

git commit -am "commit message"

Delete the branchtest

git branch -D master

Rename the current branch to masterdate

git branch -m master

Finally, force update your repositoryfile

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