1. 程式人生 > >git倉庫刪除所有提交歷史記錄,成為一個乾淨的新倉庫

git倉庫刪除所有提交歷史記錄,成為一個乾淨的新倉庫

把舊專案提交到Git上,但是會有一些歷史記錄,這些歷史記錄中可能會有專案密碼等敏感資訊。如何刪除這些歷史記錄,形成一個全新的倉庫,並且保持程式碼不變呢?

步驟和程式碼如下:


1.Checkout

   git checkout --orphan latest_branch

2. Add all the files

   git add -A

3. Commit the changes

   git commit -am "commit message"


4. Delete the branch

   git branch -D master

5.Rename the current branch to master

   git branch -m master

6.Finally, force update your repository

   git push -f origin master

原文連結:
https://yuhongjun.github.io/tech/2017/04/28/git倉庫刪除所有提交歷史記錄-成為一個乾淨的新倉庫.html