last modified by zhoutianju , 2023-06-02 00:54:42

修改提交人、邮箱

修改最近一次提交的提交人和邮箱

git commit --amend --author="username <user@host.com>"

修改历史提交记录

配合 rebase 子命令标记需要修改的提交记录为 e(edit)

git commit --amend --author="username <user@host.com>" --no-edit
git rebase --continue

修改 committer 用户名和邮箱

author 和 committer 的区别:author 为代码的作者,committer 是允许这次提交的人,一般是一个人,可参考:https://stackoverflow.com/a/18754896/11235455

可使用以下命令查看历史提交中的 author 和 committer(默认只显示 author):

git log --pretty=full

复制以下脚本在 repo 目录下执行

#!/bin/sh
git filter-branch --env-filter '
OLD_EMAIL="zhoutianju@xxx.com"
CORRECT_NAME="zhoutianju"
CORRECT_EMAIL="tianju.zhou@gmail.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



Copyright © 2023 zhoutianju.
All rights reserved.

results matching ""

    No results matching ""