git刪除所有歷史提交記錄,只留下最新的干凈代碼

1、批量修改git commit的作者信息

git filter-branch --env-filter 'export GIT_AUTHOR_EMAIL=new_email' --
git filter-branch --env-filter 'export GIT_COMMITTER_EMAIL=new_email' --
git push -f origin master

除了GIT_AUTHOR_EMAIL, 還有GIT_AUTHOR_NAME, GIT_COMMITTER_EMAIL, GIT_COMMITTER_NAME等參數(shù)可以修改.

Author是最初寫(xiě)這個(gè)commit的人, 而committer是提交這個(gè)commit的人. 對(duì)于私人項(xiàng)目來(lái)說(shuō), author和committer都是你自己. 但是如果是多人合作項(xiàng)目, 有一個(gè)人提交了PR到你的項(xiàng)目中, 最終是你進(jìn)行的commit, 那么author和committer就會(huì)不一樣.

2、刪除記錄

1.Checkout

   git checkout --orphan latest_branch
  1. Add all the files
   git add -A
  1. Commit the changes
   git commit -am "commit message"
  1. 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

3、拉取合并

拉取

git pull origin master --allow-unrelated-histories

合并master

git merge master
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容