Git推送提示缺少Change-Id,但提交信息中已存在该标识
Let’s break down what’s happening here and get this sorted out step by step:
Why This Error Pops Up
Your local HEAD commit does have a Change-Id, but Gerrit is flagging a different commit (72fe4c9) as missing it. That means there’s at least one older commit in your push sequence (the set of commits you’re trying to send to Gerrit) that doesn’t have a valid Change-Id in its message footer.
Step-by-Step Solution
1. Install the Gerrit Commit Hook (Prevent Future Issues)
Gerrit provides a hook that automatically adds a valid Change-Id to every commit message. Run the command Gerrit suggested to set it up:
gitdir=$(git rev-parse --git-dir); scp -p -P 29418 yyyyyy@gerrit.xyz.se:hooks/commit-msg ${gitdir}/hooks/
This ensures you won’t run into the same problem with future commits.
2. Find the Problematic Commit
List all commits you’re trying to push (the ones ahead of origin/master) to spot which one lacks a Change-Id:
git log origin/master..HEAD --format="%h %s%n%b"
Look for any commit that doesn’t end with a standalone line like Change-Id: Ixxxxxxxxx... (it needs to be a separate line at the very end of the commit message).
3. Fix the Commit(s)
There are two common scenarios here:
Scenario A: Only one problematic commit
If there’s just one commit missing the Change-Id, amend it directly:
git commit --amend
Your editor will open the commit message. If you installed the hook, it’ll automatically add a valid Change-Id at the bottom. If not, manually add a line at the very end (make sure it’s on its own line):
Change-Id: I<your-unique-40-hex-characters>
Save and exit the editor.
Scenario B: Multiple problematic commits
Use interactive rebase to fix each commit one by one:
- Start the rebase process:
git rebase -i origin/master - In the editor that opens, change
picktoeditnext to every commit that needs a Change-Id. Save and exit. - For each "edited" commit, run:
The hook will add the Change-Id automatically, or you can add it manually as above.git commit --amend - After amending, continue the rebase:
Repeat until the rebase finishes successfully.git rebase --continue
4. Push Your Changes Again
Once all commits have valid Change-Ids, push to Gerrit again:
git push origin HEAD:refs/for/master
Quick Tips
- Change-Ids must be on their own line at the very end of the commit message footer—they can’t be mixed with other text.
- If you’re updating an existing Gerrit review, reuse the original Change-Id to link your new commits to the same review thread.
内容的提问来源于stack exchange,提问作者Ray

