更改git作者名称和邮箱以及历史提交

Code 代码
/ git
2018年9月27日 ~

修改所有历史commits的name和email

使用以下脚本即可实现,不过需要修改以下几个参数:

  • OLD_EMAIL: 需要修改的旧邮箱地址
  • CORRECT_NAME: 需要修改成哪个名字
  • CORRECT_EMAIL: 需要修改成哪个邮箱
git filter-branch -f --env-filter '

OLD_EMAIL="old-email@example.com"
CORRECT_NAME="example"
CORRECT_EMAIL="new-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

修改完成后,再执行:

git push --force --tags origin 'refs/heads/*'

大功告成!

全局修改git的name和email


$ git config --global user.name "Jerry"
$ git config --global user.email "jerry@wjz.im"

在git repo层面修改git的name和email

$ git config user.name "Jerry"
$ git config user.email "jerry@wjz.im"

仅在某次提交试用特定的name和email

git commit --author="Jerry <jerry@wjz.im>"

版本控制

Version Action Time
1.0 Init 2018-09-28

标签

Jerry

大道至简,行者无疆。

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.