更改所有提交的 git 作者信息对我的一个回购有效,但对其他回购无效,为什么?
Changing git author info on all commits worked on one of my repos but not the others, why?
我有各种私人 GitHub repos and use Sublime Merge 来管理我的提交。
我想更改所有以前的提交作者详细信息:
发件人姓名:This,电子邮件:this@domain.com
收件人:姓名:那个,电子邮件:那个@domain.com
因此,我遵循了 GitHub 中的 these instructions 并将代码修改为以下内容:
#!/bin/sh
git filter-branch -f --env-filter '
CORRECT_NAME="That"
CORRECT_EMAIL="that@domain.com"
export GIT_AUTHOR_NAME="$CORRECT_NAME"
export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
' --tag-name-filter cat -- --branches --tags
在其中一个 repos 上这是有效的,在我使用来自指令的 git push --force --tags origin 'refs/heads/*'
之前,Sublime Merge 显示了潜在的变化,在 运行 推送之后,所有提交现在都更新为所需的详细信息。
一切都很好,所以我想,直到我用我的其他几个存储库尝试了这个并且在 sublime 中没有显示任何变化并且推送没有任何作用。我不知道为什么会有差异。其他存储库的相似之处在于它们都有相同的原始提交者。
为什么这对其他存储库不起作用?我该如何修复才能进行更改?
我发现我没有包括 AUTHOR
和 COMMITTER
详细信息:
在 repo 目录中的终端中:
git filter-branch -f --env-filter "GIT_AUTHOR_NAME='New Name'; GIT_AUTHOR_EMAIL='new@email.com'; GIT_COMMITTER_NAME='New Name'; GIT_COMMITTER_EMAIL='new@email.com';" HEAD
然后:
git push --force --tags origin 'refs/heads/*'
更好的选择是使用新工具 git filter-repo
, which replaces BFG and git filter-branch
。
见其user manual.
To modify username and emails of commits, you can create a mailmap file in the format accepted by git-shortlog
.
For example, if you have a file named my-mailmap you can run
git filter-repo --mailmap my-mailmap
and if the current contents of that file are as follows (if the specified mailmap file is version controlled, historical versions of the file are ignored):
Correct Name <correct@email.com> <old@email.com>
then we can update username and/or emails based on the specified mapping.
有关邮件映射文件的确切语法,请参阅 git shortlog
"mapping author" section。
或者,callbacks:
git-filter-repo --name-callback 'return name.replace(b"OldName", b"NewName")' \
--email-callback 'return email.replace(b"old@email.com", b"new@email.com")'
我有各种私人 GitHub repos and use Sublime Merge 来管理我的提交。
我想更改所有以前的提交作者详细信息:
发件人姓名:This,电子邮件:this@domain.com
收件人:姓名:那个,电子邮件:那个@domain.com
因此,我遵循了 GitHub 中的 these instructions 并将代码修改为以下内容:
#!/bin/sh
git filter-branch -f --env-filter '
CORRECT_NAME="That"
CORRECT_EMAIL="that@domain.com"
export GIT_AUTHOR_NAME="$CORRECT_NAME"
export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
' --tag-name-filter cat -- --branches --tags
在其中一个 repos 上这是有效的,在我使用来自指令的 git push --force --tags origin 'refs/heads/*'
之前,Sublime Merge 显示了潜在的变化,在 运行 推送之后,所有提交现在都更新为所需的详细信息。
一切都很好,所以我想,直到我用我的其他几个存储库尝试了这个并且在 sublime 中没有显示任何变化并且推送没有任何作用。我不知道为什么会有差异。其他存储库的相似之处在于它们都有相同的原始提交者。
为什么这对其他存储库不起作用?我该如何修复才能进行更改?
我发现我没有包括 AUTHOR
和 COMMITTER
详细信息:
在 repo 目录中的终端中:
git filter-branch -f --env-filter "GIT_AUTHOR_NAME='New Name'; GIT_AUTHOR_EMAIL='new@email.com'; GIT_COMMITTER_NAME='New Name'; GIT_COMMITTER_EMAIL='new@email.com';" HEAD
然后:
git push --force --tags origin 'refs/heads/*'
更好的选择是使用新工具 git filter-repo
, which replaces BFG and git filter-branch
。
见其user manual.
To modify username and emails of commits, you can create a mailmap file in the format accepted by
git-shortlog
.
For example, if you have a file named my-mailmap you can rungit filter-repo --mailmap my-mailmap
and if the current contents of that file are as follows (if the specified mailmap file is version controlled, historical versions of the file are ignored):
Correct Name <correct@email.com> <old@email.com>
then we can update username and/or emails based on the specified mapping.
有关邮件映射文件的确切语法,请参阅 git shortlog
"mapping author" section。
或者,callbacks:
git-filter-repo --name-callback 'return name.replace(b"OldName", b"NewName")' \
--email-callback 'return email.replace(b"old@email.com", b"new@email.com")'