我有很多承诺。但我的最后一次提交没有 Change-Id。 An 无法推送到 Gerrit。
如何将 Change-Id 添加到之前的提交中?
首先,您需要安装“commit-msg”挂钩,它负责自动将 Change-Ids 添加到您的提交中。要安装并了解有关该挂钩的更多信息,请参阅 Gerrit 文档中的 commit-msg Hook 项。
要更改您的最后一次提交,只需执行:
git commit --amend
或者,您可以手动将 Change-Id 添加到提交消息中。只需在提交消息页脚添加如下行:
Change-Id: Ic8aaa0728a43936cd4c6e1ed590e01ba8f0fbf5b
随机更改一些 Change-Id 数字,保留开头的“I”。
commit-msg
挂钩脚本,它将自动将更改 ID 添加到您的提交中。
我链接的文档提供了安装说明:
要获取 commit-msg 脚本,请使用 scp、wget 或curl 将其从 Gerrit 服务器下载到本地系统。
您可以使用以下任一命令:
$ 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
添加到消息中。
在处理 gerrit 更改时使用 git-review。修改并将更改提交到存储库更容易。
pip install --user git-review
git review -s # this step does the same thing as @larsks
git commit -s --amend # adds the change-id