如何使用过滤器分支更改多个提交的提交作者? [英] How to change commit author for multiple commits using filter branch?
问题描述
我正在使用在此链接中找到的脚本进行编辑所有提交中的作者信息.
#!/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
但是,我收到以下错误(警告?):
Cannot create a new backup.
A previous backup already exists in refs/original/
Force overwriting the backup with -f
我也检查了日志.作者信息未更改.我在这里做错了什么?
更新:如 @elpiekay 所述,-f
标志构成了脚本工作.
但是任何人都可以解释错误日志本身吗?为什么提到备份?我以前从未做过任何备份(不确定错误日志中将引用哪个备份)
实际上,更好的做法是:
- 对新克隆的存储库执行过滤器
- 不再不再使用git filter-branch,声明为(截至Git 2.24,Q4 2019)已经过时了.
您可以立即使用其可能的后继产品: newren/git-filter-repo
(在Python中)及其 git shortlog
映射作者部分. >
I am using this script found at this link to edit author info across all commits.
#!/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
However, I am getting the following error(warning?):
Cannot create a new backup.
A previous backup already exists in refs/original/
Force overwriting the backup with -f
I checked the log too. The author info didn't change. What am I doing wrong here?
Update: As mentioned by @elpiekay, the -f
flag made the script work.
But can anyone explain the error log itself? Why does it mention about backup ? I never made any backup before (unsure what backup is being referred in the error log)
Actually, a better practice is to:
- perform a filter on a freshly cloned repository
- not used git filter-branch anymore, which is declared (as of Git 2.24, Q4 2019) as somewhat deprecated.
You can instead used right now its possible successor: newren/git-filter-repo
(in Python), and its example section:
cd repo
git filter-repo --mailmap my-mailmap
with my-mailmap
:
Correct Name <correct@email.com> <old@email.com>
That would replace the author name and email of any commit done by anyone with <old@email.com>
See git shortlog
mapping author section for the exact syntax of
这篇关于如何使用过滤器分支更改多个提交的提交作者?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!