问题描述
是否可以通过 git filter-branch
?
的单次传递来批量重命名2个或更多电子邮件地址
我尝试通过复制 if..fi子句来修改
您只需要一个 git commit-tree
命令,根据需要变量。例如,您的提交过滤器可能会读取这样的内容:
git filter-branch -f --commit-filter'
if [$ GIT_COMMITTER_NAME=< Old Name 1> ]。那么
GIT_COMMITTER_NAME =< New Name 1>;
GIT_AUTHOR_NAME =< New Name 1>;
GIT_COMMITTER_EMAIL =<新邮件1>;
GIT_AUTHOR_EMAIL =<新邮件1>;
fi;
if [$ GIT_COMMITTER_NAME=< Old Name 2> ]。然后
GIT_COMMITTER_NAME =< New Name 2>;
GIT_AUTHOR_NAME =<新名称2>;
GIT_COMMITTER_EMAIL =<新邮件2>;
GIT_AUTHOR_EMAIL =<新邮件2>;
fi;
git commit-tree$ @
'
(虽然如果更改名称的数量会变得更高我可能会通过映射文件运行,而不是一系列易于打印的错误 if ... then
s,可能会更有意义,分别映射作者和提交者)。
请记住 filter-branch
简单地副本在创建< old-sha1的映射时,您告诉它复制的所有提交(通过使用 git commit-tree
创建新副本)新-SHA1>对。这就是为什么提交两个提交不好:一个现有的(旧)SHA-1现在必须映射到两个新的副本,根据 filter-branch
使用提交图。 (如果您在复制过程中选择省略某些提交,则多个旧的SHA-1可以映射到一个新的SHA-1。也就是说,新图可以是双射或全射图,分支并不真正相信内射,因为它会尝试将旧引用映射到新图。)
Is it possible to mass-rename 2 or more email addresses with a single pass of git filter-branch
?
I tried adapting the code from this answer by just duplicating the if..fi clause
:
git filter-branch --commit-filter '
if [ "$GIT_COMMITTER_NAME" = "<Old Name 1>" ];
then
GIT_COMMITTER_NAME="<New Name 1>";
GIT_AUTHOR_NAME="<New Name 1>";
GIT_COMMITTER_EMAIL="<New Email 1>";
GIT_AUTHOR_EMAIL="<New Email 1>";
git commit-tree "$@";
else
git commit-tree "$@";
fi
if [ "$GIT_COMMITTER_NAME" = "<Old Name 2>" ];
then
GIT_COMMITTER_NAME="<New Name 2>";
GIT_AUTHOR_NAME="<New Name 2>";
GIT_COMMITTER_EMAIL="<New Email 2>";
GIT_AUTHOR_EMAIL="<New Email 2>";
git commit-tree "$@";
else
git commit-tree "$@";
fi' HEAD
But it gave me errors during the filter-branch that looked like this:
error: duplicate parent bc8f9924c33558a275b8f694969529cf56232c80 ignored
And then the branch history was all tangled up:
You want just one git commit-tree
command, after setting all the environment variables as desired. For instance, your commit filter might read something like this:
git filter-branch -f --commit-filter '
if [ "$GIT_COMMITTER_NAME" = "<Old Name 1>" ]; then
GIT_COMMITTER_NAME="<New Name 1>";
GIT_AUTHOR_NAME="<New Name 1>";
GIT_COMMITTER_EMAIL="<New Email 1>";
GIT_AUTHOR_EMAIL="<New Email 1>";
fi;
if [ "$GIT_COMMITTER_NAME" = "<Old Name 2>" ]; then
GIT_COMMITTER_NAME="<New Name 2>";
GIT_AUTHOR_NAME="<New Name 2>";
GIT_COMMITTER_EMAIL="<New Email 2>";
GIT_AUTHOR_EMAIL="<New Email 2>";
fi;
git commit-tree "$@"
'
(although if the number of name changes to make gets higher I'd probably run through a mapping file instead of a long series of easy-to-typo if ... then
s, and it might make more sense to map author and committer separately).
Remember that filter-branch
simply copies all the commits you tell it to copy (by using git commit-tree
to make the new copy), while building a map of <old-sha1,new-sha1> pairs. This is why making two commits is not good: one existing (old) SHA-1 now has to map to two new copies, which is simply not allowed in terms of what filter-branch
does with the commit graph. (Multiple old SHA-1s can map to a single new SHA-1, if you choose to omit some commits during the copying process. That is, the new graph can be bijective or surjective, but filter-branch doesn't really believe in injective, as it's going to try to map the old references to the new graph.)
这篇关于重命名多个名称和电子邮件在git-filter-branch的单个过程中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!