我想重写存储库中所有提交的作者/提交者电子邮件和名称。我正在使用这个很好的答案:
git filter-repo --commit-callback '
if commit.author_email == b"incorrect@email":
commit.author_email = b"correct@email"
commit.author_name = b"Correct Name"
commit.committer_email = b"correct@email"
commit.committer_name = b"Correct Name"
'
但是,而不是每次都手动编辑命令来插入
incorrect@email
)correct@email
)Correct Name
)我想将此命令放入 bash 脚本中。该脚本必须包含这些参数的默认值,这样,如果在不提供任何输入参数的情况下运行它,它将使用默认参数运行。我怎样才能做到这一点?
您可以通过在回调中使用
elif
和 else
一次性完成这一切,如 git-filter-repo
文档示例中所示,如下所示:
--------------------------------------------------
git-filter-repo --filename-callback '
if commit.author_email == b"incorrect1@email"
# change it
elif commit.author_email == b"incorrect2@email"
# change it
else:
# put default here
'
--------------------------------------------------
在
elif
块中添加额外交换,并在 else
块中添加默认交换。
旁注: 在您问题的示例中,您仅根据作者设置作者和提交者。也许它们在你的仓库中总是相同的,在这种情况下这并不重要。如果它们确实不同,您可能希望单独处理它们。