1. 程式人生 > >ERROR: missing Change-Id in commit message footer

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 即可.