将 Change-Id 添加到上一次提交

Add Change-Id to previous commit

我有很多承诺。但是我最后一次提交没有更改 ID。无法推送到 Gerrit。

如何将 Change-Id 添加到之前的提交中?

首先,您需要安装 "commit-msg" 挂钩,它负责自动将 Change-Ids 添加到您的提交中。要安装和了解有关挂钩的更多信息,请参阅 Gerrit 文档中的 commit-msg Hook 项。

要更改您的最后一次提交,只需执行:

git commit --amend

或者,您可以手动将 Change-Id 添加到您的提交消息中。只需在提交消息页脚添加一行,如下所示:

Change-Id: Ic8aaa0728a43936cd4c6e1ed590e01ba8f0fbf5b

随机更改一些 Change-Id 数字,保持开头的 "I"。

Gerrit 提供了一个 commit-msg hook script,它会自动将更改 ID 添加到您的提交中。

我链接到的文档提供了安装说明:

To obtain the commit-msg script use scp, wget or curl to download it to your local system from your Gerrit server.

You can use either of the below commands:

$ scp -p -P 29418 <your username>@<your Gerrit review server>:hooks/commit-msg <local path to your git>/.git/hooks/

$ curl -Lo <local path to your git>/.git/hooks/commit-msg <your Gerrit http URL>/tools/hooks/commit-msg

安装 commit-msg 钩子后,您可以使用 git commit --amend 更新您的提交信息;当您保存它时,挂钩会将 Change-Id 添加到消息中。