Change email on git commits?
This question already has an answer here:
git filter-branch
should be able to do this for you; essentially it rewrites the entire commit history of the branch with the same SHA1's.
There's an example script on Github that demonstrates how to do this; it's short, so I'm reproducing it here.
#!/bin/sh
git filter-branch --env-filter '
OLD_EMAIL="your-old-email@example.com"
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="your-correct-email@example.com"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_AUTHOR_NAME="$CORRECT_NAME"
export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags
It will be necessary to force push the filtered branch, as you've changed history on it. If anyone is sharing your branch, that will make their history and yours mismatch -- you'll need to have all your collaborators re-pull the edited branch. If they've been working on the old branch and have made commits on it, they can cherry-pick those onto the new branch.
You may want to make this easier by creating a whole new branch and updating history there, then letting everyone pull it. At that point you can all agree that this is the new master branch and work on that basis, or simply have everyone delete their copy of the old master and rename the new branch to master
.
上一篇: Python类实例变量隔离
下一篇: 更改电子邮件git提交?