我想改变历史上某个特定承诺的作者。这不是最新的承诺。
相关:如何更改多次提交的作者和提交人姓名/电子邮件?
我想改变历史上某个特定承诺的作者。这不是最新的承诺。
相关:如何更改多次提交的作者和提交人姓名/电子邮件?
当前回答
可选:如果不想将本地更改发送到远程,请确保将其隐藏。
$ git status
$ git stash
更新上次提交的作者。
$ git log // Old author in local and remote
$ git commit --amend --author="Author Name <email@address.com>"
$ git log // New Author in local
$ git push origin <branch> --force-with-lease
$ git log // New Author in remote
然后,如果您使用git stash,则恢复您的暂存更改
$ git stash pop
$ git status
然后,您应该为当前项目的下一次提交更新配置。
$ git config user.name "Author Name"
$ git config user.email "<email@address.com>"
并使用git-config-edit检查或编辑
澄清:在使用$ggpush-f丢失提交的罕见情况下,您可以使用reflog恢复它们。无论如何,在租约中使用--force比只使用-f更能保护您
GL
来源ZSH公司
其他回答
如果您只想更改上次提交的作者,可以执行以下操作:
将电子邮件重置为全局配置:git-config--全局用户电子邮件example@email.com现在重置提交的作者,无需编辑:gitcommit--修改--重置作者--无编辑
注意,这也会更改作者时间戳。
您可以从github的官方页面使用这些命令
https://help.github.com/en/github/using-git/changing-author-info
这是命令
#!/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 rebase -i -p <some HEAD before all of your bad commits>
然后在rebase文件中将所有错误提交标记为“edit”,当git要求您修改每个提交时
git commit --amend --author "New Author Name <email@address.com>"
编辑或关闭打开的编辑器,然后执行
git rebase --continue
以继续重新启动。
您可以通过附加--no edit来跳过在此处完全打开编辑器,这样命令将是:
git commit --amend --author "New Author Name <email@address.com>" --no-edit && \
git rebase --continue
单次提交
正如一些评论所指出的,如果您只想更改最近的提交,那么rebase命令是不必要的。就这样吧
git commit --amend --author "New Author Name <email@address.com>"
这会将author更改为指定的名称,但committer将设置为gitconfig user.name和gitconfig user.email中配置的用户。如果要将committer设置为指定的值,这将同时设置author和committer:
git -c user.name="New Author Name" -c user.email=email@address.com commit --amend --reset-author
可选:如果不想将本地更改发送到远程,请确保将其隐藏。
$ git status
$ git stash
更新上次提交的作者。
$ git log // Old author in local and remote
$ git commit --amend --author="Author Name <email@address.com>"
$ git log // New Author in local
$ git push origin <branch> --force-with-lease
$ git log // New Author in remote
然后,如果您使用git stash,则恢复您的暂存更改
$ git stash pop
$ git status
然后,您应该为当前项目的下一次提交更新配置。
$ git config user.name "Author Name"
$ git config user.email "<email@address.com>"
并使用git-config-edit检查或编辑
澄清:在使用$ggpush-f丢失提交的罕见情况下,您可以使用reflog恢复它们。无论如何,在租约中使用--force比只使用-f更能保护您
GL
来源ZSH公司
在全球范围内更改提交人姓名和电子邮件:
$ git config --global user.name "John Doe"
$ git config --global user.email "john@doe.org"
更改每个存储库的提交人名称和电子邮件:
$ git config user.name "John Doe"
$ git config user.email "john@doe.org"
仅为下一次提交更改作者信息:
$ git commit --author="John Doe <john@doe.org>"
提示:对于其他情况和阅读更多信息,请阅读帖子参考。