如何将 gerrit 更改 ID 添加到旧提交?

How to add gerrit change ID to an older commit?

很少有返回的提交,我做了一个没有更改 ID 的提交。不幸的是,每当您在没有取消选中 "Commit merge immediately".

的情况下合并源代码树中的分支时,就会发生这种情况

我现在迫切需要将代码推送到 Gerrit,但我不能,因为其中一个提交没有更改 ID。

如何将更改 ID 重新添加到旧提交?

假设提交历史是 A-B-C-D-E 并且缺少 B 中的更改 ID。我不是 source-tree 用户,所以我将在终端中给出命令:

git reset B --hard
#assuming you have installed the hook commit-msg that generates the change id.
git commit --amend
git cherry-pick C D E
#OR: git cherry-pick B..E

假设 origin/master 是您正在使用的远程 HEAD,您可以在 origin/master 上进行交互式变基。您可以将 origin/master 替换为您想要的任何内容。

git rebase -i origin/master

当这样做时,在我的示例中将提示所有提交都在 origin/master 之前。您必须选择所有提交,但没有 Change-ID 的提交。对于那个,您需要编辑消息。这样做会自动添加 change-ID。

外部资源: Git interactive Rebase