ERROR: missing Change-Id in commit message footer

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

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 [email protected]:hooks/commit-msg ${gitdir}/hooks/
remote: And then amend the commit:
remote:   git commit --amend
remote:
To ssh://[email protected]:29419/XXX
 ! [remote rejected] HEAD -> refs/for/4.2 (missing Change-Id in commit message footer)
error: failed to push some refs to 'ssh://[email protected]:29419/XXX'

不要焦急,因为我也遇到了,下面是解决方案:

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

如果该文件不存在,则按照 git push 时产生的提示信息,获取该文件:
$ gitdir=$(git rev-parse --git-dir);scp-p -P 29418 [email protected]:hooks/commit-msg${gitdir}/hooks/

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

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

该命令会打开默认的 commit message 编辑器,一般是 vi.

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

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

猜你喜欢

转载自blog.csdn.net/mt_lixinzeng/article/details/84937439