美文网首页
git删除所有历史提交记录,只留下最新的干净代码

git删除所有历史提交记录,只留下最新的干净代码

作者: yranidro | 来源:发表于2019-11-02 12:10 被阅读0次

    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等参数可以修改.

    Author是最初写这个commit的人, 而committer是提交这个commit的人. 对于私人项目来说, author和committer都是你自己. 但是如果是多人合作项目, 有一个人提交了PR到你的项目中, 最终是你进行的commit, 那么author和committer就会不一样.

    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
    

    相关文章

      网友评论

          本文标题:git删除所有历史提交记录,只留下最新的干净代码

          本文链接:https://www.haomeiwen.com/subject/jmbcbctx.html