更改Git中多个提交的作者和提交者姓名和电子邮件 [英] Change the author and committer name and e-mail of multiple commits in Git
问题描述
我在学校电脑上写了一个简单的脚本,并对Git进行了修改(在我的电脑上,这是从家里的电脑上克隆的回购)。
I was writing a simple script in the school computer, and committing the changes to Git (in a repo that was in my pendrive, cloned from my computer at home). After several commits I realized I was committing stuff as the root user.
有什么办法可以将这些提交的作者更改为我的名字吗?
Is there any way to change the author of these commits to my name?
推荐答案
更改作者(或提交者)需要重写所有历史记录。如果你没有问题,并认为它是值得的,那么你应该检查出 git filter分枝。手册页包含几个例子,以帮助您入门。另外请注意,您可以使用环境变量来更改作者,提交者,日期等的名称 - 请参阅 git手册页。
Changing the author (or committer) would require re-writing all of the history. If you're okay with that and think it's worth it then you should check out git filter-branch. The man page includes several examples to get you started. Also note that you can use environment variables to change the name of the author, committer, dates, etc. -- see the "Environment Variables" section of the git man page.
具体而言,您可以修复所有错误的作者姓名和电子邮件分支和标签(来源: GitHub帮助) :
$ b
Specifically, you can fix all the wrong author names and emails for all branches and tags with this command (source: GitHub help):
#!/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
这篇关于更改Git中多个提交的作者和提交者姓名和电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!