我想改变历史上某个特定承诺的作者。这不是最新的承诺。
相关:如何更改多次提交的作者和提交人姓名/电子邮件?
我想改变历史上某个特定承诺的作者。这不是最新的承诺。
相关:如何更改多次提交的作者和提交人姓名/电子邮件?
当前回答
找到一种可以快速改变用户并且不会对其他提交产生副作用的方法。
简单明了的方式:
git config user.name "New User"
git config user.email "newuser@gmail.com"
git log
git rebase -i 1f1357
# change the word 'pick' to 'edit', save and exit
git commit --amend --reset-author --no-edit
git rebase --continue
git push --force-with-lease
详细操作
显示提交日志,并在提交之前找出要更改的提交id:
git log
git从选择的提交id反向开始到最近的提交id:
git config user.name "New User"
git config user.email "newuser@gmail.com"
git rebase -i 1f1357
# change word pick to edit, save and exit
edit 809b8f7 change code order
pick 9baaae5 add prometheus monitor kubernetes
edit 5d726c3 fix liquid escape issue
edit 3a5f98f update tags
pick 816e21c add prometheus monitor kubernetes
rebase将在下一次提交id时停止,输出:
Stopped at 809b8f7... change code order
You can amend the commit now, with
git commit --amend
Once you are satisfied with your changes, run
git rebase --continue
确认并继续您的重新基准,直到它成功地传递给refs/heads/master。
# each continue will show you an amend message
# use git commit --amend --reset-author --no-edit to comfirm
# use git rebase --skip to skip
git commit --amend --reset-author --no-edit
git rebase --continue
git commit --amend --reset-author --no-edit
...
git rebase --continue
Successfully rebased and updated refs/heads/master.
git推送更新
git push --force-with-lease
其他回答
如果您只想更改上次提交的作者,可以执行以下操作:
将电子邮件重置为全局配置:git-config--全局用户电子邮件example@email.com现在重置提交的作者,无需编辑:gitcommit--修改--重置作者--无编辑
注意,这也会更改作者时间戳。
溶液
安装git filter repo(git项目建议在filter分支上安装filter repo)$PACKAGE_TOOL安装git筛选器repo在git存储库的根目录中创建一个文件.mailmap,其中包含新名称<new@ema.il> <old@ema.il>运行gitfilter repo--使用mailmap
更多详细信息
gitfilter repo在其文档中将其列为示例不要像上面的示例那样替换名称和电子邮件,请查看gitmailmap文档中的其他示例您可以通过使用参数--mailmap<filename>调用gitfilter repo来指定mailmap文件,而不是默认使用名为.mailmap的文件。关于如何进一步过滤分支/标签/任何内容的更多示例,可以在gitfilter repo项目的README.md中找到。
Github文档包含一个脚本,用于替换分支中所有提交的提交者信息(现在无法恢复,这是最后一个快照)。
更改变量值后,从终端运行以下脚本
#!/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
将更正的历史推送到GitHub:
git push --force --tags origin 'refs/heads/*'
或者,如果您想推送选定的分支引用,请使用
git push --force --tags origin 'refs/heads/develop'
找到一种可以快速改变用户并且不会对其他提交产生副作用的方法。
简单明了的方式:
git config user.name "New User"
git config user.email "newuser@gmail.com"
git log
git rebase -i 1f1357
# change the word 'pick' to 'edit', save and exit
git commit --amend --reset-author --no-edit
git rebase --continue
git push --force-with-lease
详细操作
显示提交日志,并在提交之前找出要更改的提交id:
git log
git从选择的提交id反向开始到最近的提交id:
git config user.name "New User"
git config user.email "newuser@gmail.com"
git rebase -i 1f1357
# change word pick to edit, save and exit
edit 809b8f7 change code order
pick 9baaae5 add prometheus monitor kubernetes
edit 5d726c3 fix liquid escape issue
edit 3a5f98f update tags
pick 816e21c add prometheus monitor kubernetes
rebase将在下一次提交id时停止,输出:
Stopped at 809b8f7... change code order
You can amend the commit now, with
git commit --amend
Once you are satisfied with your changes, run
git rebase --continue
确认并继续您的重新基准,直到它成功地传递给refs/heads/master。
# each continue will show you an amend message
# use git commit --amend --reset-author --no-edit to comfirm
# use git rebase --skip to skip
git commit --amend --reset-author --no-edit
git rebase --continue
git commit --amend --reset-author --no-edit
...
git rebase --continue
Successfully rebased and updated refs/heads/master.
git推送更新
git push --force-with-lease
推送提交后重命名作者名称的步骤
首先键入“gitlog”以获取提交id和更多详细信息git rebase i HEAD~10(10是要在rebase上显示的提交总数)如果您有以下内容致命:似乎已经有一个rebase合并目录,并且我想知道你是不是在另一个地方。如果这是箱子,请试试git rebase(--continue|--abort|--skip)如果不是这样,请rm-fr“.git/rebase合并”再跑一次。我要停下来,以防你还有事在那里很有价值。然后根据需要键入“git-rebase--continue”或“git-rebase--abort”现在您将重新创建窗口,单击键盘上的“i”键然后,您将得到提交列表为10[因为我们已经通过了上面的10个提交]如下图所示pick 897fe9e稍微简化了代码pick abb60f9添加新功能pick dc18f70错误修复现在,您需要在要编辑的提交下面添加下面的命令,如下所示pick 897fe9e稍微简化了代码exec git commit--modify--author的作者名称<author.name@mail.com>'pick abb60f9添加新功能exec git commit--modify--author的作者名称<author.name@mail.com>' pick dc18f70错误修复exec git commit--modify--author的作者名称<author.name@mail.com>'就这样,现在只需按ESC键,:wq,即可完成所有设置然后git push origin HEAD:BRANCH NAME-f[请注意-f Force push]像gitpush-f或gitpushorigin HEAD:dev-f