您的位置:首页 > 编程语言

修改 Github commit 的作者信息

2017-07-27 14:32 211 查看
原文:http://www.jianshu.com/p/b6add8187c06

配置方法:

git config --global user.email "youremail@google.com"
git config --global user.name "your name"


但是补救措施只对以后的 commit 起效。

如果想修改之前的作者信息,可以通过脚本重写历史信息:

1. 创建一个你的 repo 的全新裸 clone (repo.git 替换为你的项目,下同)

git clone --bare https://github.com/user/repo.git cd repo.git


2.复制粘贴脚本,并根据你的信息修改以下变量:

OLD_EMAIL # 历史记录中的邮箱
CORRECT_NAME # 新的用户名
CORRECT_EMAIL # 新的邮箱


脚本:

#!/bin/sh

git filter-branch --env-filter '

OLD_EMAIL="your-old-email@example.com"
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="your-correct-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


4.按 Enter 执行脚本。

5.查看新 Git 历史有没有错误。

6.把正确历史 push 到 Github:(push 有困难时记得修改 DNS 或者搭梯子)

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


7.清除临时 clone

cd ..
rm -rf repo.git
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  git 历史