刪除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
相關文章
相關標籤/搜索