公司配了台新电脑,在电脑上使用GIT提交代码前忘记配置 user信息了;
提交后发现GIT历史记录里出现了 unknown作者,老眼一花,差点没倒过去;
没办法只好查资料来修改了,幸好黄天不负有心人,被我找到了;
于是一波操作,相当顺利的改完了,这里记录分享一下,以备后来者使用;
1、第一步,查询你有git库有哪些提交者:
$ git log --pretty=full | grep -E '(Author|Commit): (.*)$' | sed 's/Author: //g' | sed 's/Commit: //g' | sort -u
山猫 <lynx.kor@163.com>
unknown <root@localhost>
2、第二步,运行下面这个脚本,记得改改里面对应的个人信息哦:
$ git filter-branch --env-filter '
if [ "$GIT_COMMITTER_EMAIL" = "root@localhost" ]; then
export GIT_COMMITTER_NAME="山猫"
export GIT_COMMITTER_EMAIL="lynx.kor@163.com"
fi
if [ "$GIT_AUTHOR_EMAIL" = "root@localhost" ]; then
export GIT_AUTHOR_NAME="山猫"
export GIT_AUTHOR_EMAIL="lynx.kor@163.com"
fi
' --tag-name-filter cat -f -- --all
3、第三步,查一下改完了没
$ git log --pretty=full | grep -E '(Author|Commit): (.*)$' | sed 's/Author: //g' | sed 's/Commit: //g' | sort -u
山猫 <lynx.kor@163.com>
4、第四步,把结果推到库里去
$ git push --force --tags origin 'refs/heads/*'
做完这一步,可以放心喝茶了
参考资料:https://www.everythingcli.org/git-like-a-pro-rewrite-author-history/