環境:【IntelliJ IDEA】 【Gerrit】
1、錯誤信息
代碼合并,迭代1合并到迭代2,解決沖突后,依然push不上去,報錯信息如下:
remote: Processing changes: refs: 1 ? ? ? ?
remote: Processing changes: refs: 1 ? ? ? ?
remote: Processing changes: refs: 1, done ? ? ? ? ? ?
remote: ERROR: commit 60bd16a: Change-Id must be in message footer ? ? ? ?
remote:?
remote: Hint: run ? ? ? ?
remote: ? git commit --amend ? ? ? ?
remote: and move 'Change-Id: Ixxx..' to the bottom on a separate line ? ? ? ?
remote:?
error: failed to push some refs to 'http://167.520.13.14:8080/test-gateway'
To http://167.520.13.14:8080/test-gateway
!?? ?refs/heads/DD_02:refs/for/DD_02?? ?[remote rejected] (commit 60bd16a: Change-Id must be in message footer)
Done
2、簡要解釋報錯原因
推送失敗的原因是提交信息中缺少或位置不正確的 Change-Id。Git服務器要求每個提交的最后必須包含單獨一行的 Change-Id,這是為了確保代碼審查和合并時的唯一標識。
3、復雜原因分點描述
Change-Id 缺失:提交信息中沒有 Change-Id。
Change-Id 位置錯誤:Change-Id 沒有放在提交信息的最后一行。
格式問題:Change-Id 格式不正確,例如不是以 Change-Id: Ixxx.. 開頭。
4、修復建議
根據提示,可以通過以下步驟修正:
(1)修改提交信息:
- ? ?git commit --amend
(2)確保 Change-Id 在最后一行:
- 打開編輯器后,將 Change-Id 移動到提交信息的最后一行,并確保它單獨成行。
- 如果沒有 Change-Id,可以使用工具生成并添加。
(3)重新推送:
- ?git push origin refs/heads/DD_02:refs/for/DD_02
5、其他注意事項
如果你使用的是 Gerrit 代碼審查系統,通常會自動生成 Change-Id。如果你手動修改了提交信息,可能會導致 Change-Id 丟失或位置不對。
確保在每次提交時都遵循項目的提交規范,特別是對于需要代碼審查的項目。