之前填写的信息错误,需要把信息修正下。
修改当前仓提交人信息
先修改当前仓提交人信息,避免以后再使用全局提交人信息。
cd your-repo
git config user.name # 查看当前提交人名称
git config user.name "jeeinn" # 修改
git config user.email # 查看当前提交人邮箱
git config user.email "thinkwei2012@gmail.com"
修改全局的请添加 --global
参数
修改历史提交人信息
使用 git filter-branch
内置命令:
注意会有提醒。
WARNING: git-filter-branch has a glut of gotchas generating mangled history
rewrites. Hit Ctrl-C before proceeding to abort, then use an
alternative filtering tool such as 'git filter-repo'
(https://github.com/newren/git-filter-repo/) instead. See the
filter-branch manual page for more details; to squelch this warning,
set FILTER_BRANCH_SQUELCH_WARNING=1.
脚本内容:
#!/bin/sh
git filter-branch --env-filter '
OLD_EMAIL="old@email.com"
CORRECT_NAME="jeeinn"
CORRECT_EMAIL="thinkwei2012@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
Git现在推荐使用 git filter-repo
工具来代替 git filter-branch
,因为它更安全、更快速。
脚本如下,可能需要额外安装 git-filter-repo:(2025年8月14日更)
#!/bin/bash
# 直接使用 --commit-callback 一次性修改
git filter-repo --commit-callback '
if commit.committer_email == b"old@email.com":
commit.committer_name = b"jeeinn"
commit.committer_email = b"thinkwei2012@gmail.com"
if commit.author_email == b"old@email.com":
commit.author_name = b"jeeinn"
commit.author_email = b"thinkwei2012@gmail.com"
'
Git 修改提交人信息,到此结束了