Change git email for previous commits

后端 未结 2 1695
情深已故
情深已故 2020-12-24 15:19

So I read a lot about how to change previous commit\'s email address but for some reason mine is not updating.

I did like 40 commits to my private repo with my loca

相关标签:
2条回答
  • 2020-12-24 15:44

    As you mentioned in your question (the link to the answer you found), this is the script indeed.

    Note:

    filter-branch is doing a rebase (will rewrite the history of the branch) which means that everyone who had a copy of the branch will have to delete and checkout it again.


    The script origin is from here - Git-Tools-Rewriting-History:

    # Loop over all the commits and use the --commit-filter
    # to change only the email addresses
    
    git filter-branch --commit-filter '
    
        # check to see if the committer (email is the desired one)
        if [ "$GIT_COMMITTER_EMAIL" = "<Old Email>" ];
        then
                # Set the new desired name
                GIT_COMMITTER_NAME="<New Name>";
                GIT_AUTHOR_NAME="<New Name>";
    
                # Set the new desired email
                GIT_COMMITTER_EMAIL="<New Email>";
                GIT_AUTHOR_EMAIL="<New Email>";
    
                # (re) commit with the updated information
                git commit-tree "$@";
        else
                # No need to update so commit as is
                git commit-tree "$@";
        fi' 
    HEAD
    

    What does the script do?

    Its looping over all your commits and once you find match its replacing the name and email of the committer.

    0 讨论(0)
  • 2020-12-24 15:51

    You can indeed do his for many commits at once like this:

    git rebase -i HEAD~40 -x "git commit --amend --author 'Author Name <author.name@mail.com>' --no-edit"
    

    I worked this out better in this answer.

    0 讨论(0)
提交回复
热议问题