Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git 修改历史 commits 中的用户名和邮箱 #5

Open
BUPTlhuanyu opened this issue Sep 8, 2021 · 0 comments
Open

Git 修改历史 commits 中的用户名和邮箱 #5

BUPTlhuanyu opened this issue Sep 8, 2021 · 0 comments

Comments

@BUPTlhuanyu
Copy link
Owner

BUPTlhuanyu commented Sep 8, 2021

安全起见,确保你的仓库是新 clone 的,并且没有新的提交

git config user.name xxx
git config user.email [email protected]
  1. git log 查看需要替换的邮箱,并填入下面的 OLD_EMIAL,用于替换的用户名和邮箱分别填入 CORRECT_NAME 以及 CORRECT_EMAIL
git filter-branch -f --env-filter '
OLD_EMAIL="[email protected]"
CORRECT_NAME="xxx"
CORRECT_EMAIL="[email protected]"
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
  1. 在仓库目录运行上面脚本
  2. git log 查看是否修正成功
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant