ERROR: missing Change-Id in commit message footer

你用 git push 向 gerrit 提交了待审核代码,出现下面的状况:git

remote: Resolving deltas: 100% (3/3)
remote: Processing changes: refs: 1, done    
remote: ERROR: missing Change-Id in commit message footer
remote:
remote: Hint: To automatically insert Change-Id, install the hook:
remote:   gitdir=$(git rev-parse --git-dir); scp -p -P 29419 lixinzeng@10.60.242.20:hooks/commit-msg ${gitdir}/hooks/
remote: And then amend the commit:
remote:   git commit --amend
remote:
To ssh://XXX@XX.XX.XX.XX:29419/XXX
 ! [remote rejected] HEAD -> refs/for/4.2 (missing Change-Id in commit message footer)
error: failed to push some refs to 'ssh://XXX@XX.XX.XX.XX:29419/XXX'ssh

不要焦急,由于我也遇到了,下面是解决方案:编辑器

使用ls命令检查该文件是否存在:
$ cd project_dir
$ ls .git/hooks/commit-msgrem

若是该文件不存在,则按照 git push 时产生的提示信息,获取该文件:
$ gitdir=$(git rev-parse --git-dir);scp-p -P 29418 xx@gerrit.xxxxx.com:hooks/commit-msg${gitdir}/hooks/it

上面的命令能够直接从 git push 产生的错误信息中复制出来.call

若是缺失 Change-Id 的是最后一个 (head) commit, 使用如下命令便可解决问题:
$ git commit --amenderror

该命令会打开默认的 commit message 编辑器,通常是 vi.di

这时什么都不用修改,直接保存退出便可 (Ctrl+x).文件

再次查看 git log,就会发现缺失的 Change-Id 已经被补上了. 再次 git push 便可.vi