我想改变历史上某个特定承诺的作者。这不是最新的承诺。
相关:如何更改多次提交的作者和提交人姓名/电子邮件?
我想改变历史上某个特定承诺的作者。这不是最新的承诺。
相关:如何更改多次提交的作者和提交人姓名/电子邮件?
当前回答
提交时间:
要修复所有提交的作者,您可以从@Amber的回答中应用命令:
git commit --amend --author="Author Name <email@address.com>"
或者,要重复使用您的姓名和电子邮件,您只需写下:
git commit --amend --author=Eugen
命令后提交:
例如,从4025621开始更改所有:
您必须运行:
git rebase --onto 4025621 --exec "git commit --amend --author=Eugen" 4025621
注意:要包含包含空格(如姓名和电子邮件地址)的作者,作者必须用转义引号括起来。例如:
git rebase --onto 4025621 --exec "git commit --amend --author=\"Foo Bar <foo@bar.com>\"" 4025621
或将此别名添加到~/.gitconfig中:
[alias]
reauthor = !bash -c 'git rebase --onto $1 --exec \"git commit --amend --author=$2\" $1' --
然后运行:
git reauthor 4025621 Eugen
其他回答
有一个快捷方式适用于投票最多的问题:使用exec而不是edit。
exec允许对指定的提交运行命令。使用它可以避免使用edit、退出终端并为每个git提交运行git命令。如果您必须更改历史记录中的多次提交,这尤其有用。
步骤如下:
执行对早期提交的重新基础(gitrebase-i<earliercommit>)在打开的编辑器中,在要编辑的每个提交行后添加一行,然后添加exec git commit--modify--author=“作者名称<email@address.com>“--不编辑(如果要重置为gitconfig中设置的值,请使用--reset-author)”保存并退出-这将为每次提交运行指定的命令,有效地更改作者
编辑器内容示例(更改前两个提交作者):
pick 1fc6c95 Patch A
exec git commit --amend --author="Author Name <email@address.com>" --no-edit
pick 6b2481b Patch B
exec git commit --amend --author="Author Name <email@address.com>" --no-edit
pick dd1475d something I want to split
pick c619268 A fix for Patch B
pick fa39187 something to add to patch A
pick 4ca2acc i cant' typ goods
pick 7b36971 something to move before patch B
# Rebase 41a72e6..7b36971 onto 41a72e6
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#
如果您需要更改的是上一次提交的作者,而没有其他人正在使用您的存储库,您可以使用以下方法撤消上一次的提交:
git push -f origin last_commit_hash:branch_name
更改提交的作者名称:
git commit --amend --author "type new author here"
退出打开的编辑器并再次推送代码:
git push
对于合并提交消息,我发现我不能通过使用rebase来修改它,至少在gitlab上是这样。它将合并显示为提交,但我无法重新基于该#sha。我发现这篇文章很有用。
git checkout <sha of merge>
git commit --amend # edit message
git rebase HEAD previous_branch
这三行代码完成了更改合并提交消息的工作(如作者)。
提交时间:
要修复所有提交的作者,您可以从@Amber的回答中应用命令:
git commit --amend --author="Author Name <email@address.com>"
或者,要重复使用您的姓名和电子邮件,您只需写下:
git commit --amend --author=Eugen
命令后提交:
例如,从4025621开始更改所有:
您必须运行:
git rebase --onto 4025621 --exec "git commit --amend --author=Eugen" 4025621
注意:要包含包含空格(如姓名和电子邮件地址)的作者,作者必须用转义引号括起来。例如:
git rebase --onto 4025621 --exec "git commit --amend --author=\"Foo Bar <foo@bar.com>\"" 4025621
或将此别名添加到~/.gitconfig中:
[alias]
reauthor = !bash -c 'git rebase --onto $1 --exec \"git commit --amend --author=$2\" $1' --
然后运行:
git reauthor 4025621 Eugen
如果您的机器上缺少设置,例如,在格式化之后,或者在没有正确设置(正确)这些命令的情况下没有正确配置Git,则可能会发生这种情况。
git config user.name "Author Name"
git config user.email "<email@address.com>"
为什么不遵循Atlassian的这篇文章,让你的生活更简单?
gitcommit--modify--author=“作者名称<email@address.com>"如果分支受到保护,请取消对其的保护。在本例中,它是master;因此,它将受到源代码存储库的保护git推送原点master—力
这是最后一次提交的最简单场景。要选择任何“随机”提交,您需要:
git rebase-i<早期提交>。更改您感兴趣的提交的编辑选择gitcommit--modify--author=“作者名称<email@address.com>"如果分支受到保护,请取消对其的保护。在本例中,它是master;因此,它将受到源代码存储库的保护git推送原点master—力
在推送之前,您可以随时在两者之间进行git登录,以确定您所在的位置。