以这个github commit为例:
如果由于某种原因,需要删除上图高亮的提交者用户名和提交者邮箱地址,应该如何操作呢?
下面是我联系了Github support之后得到的解决方案:
注意事项
Running this script rewrites history for all repository collaborators. After completing these steps, any person with forks or clones must fetch the rewritten history and rebase any local changes into the rewritten history.
1 - Before running this script, you’ll need:
- The old email address that appears in the author/committer fields that you want to change
- The correct name and email address that you would like such commits to be attributed to
2 - Create a fresh, bare clone of your repository:
git clone --bare https://github//.git
cd .git
3 - Copy and paste the script, replacing the following variables based on the information you gathered:
- OLD_EMAIL
- CORRECT_NAME
- CORRECT_EMAIL
#!/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
4 - Press Enter to run the script.
5 - Review the new Git history for errors.
6 - Push the corrected history to :
git push --force --tags origin ‘refs/heads/*’
7 - Clean up the temporary clone:
cd ..
rm -rf <reponame>.git