Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gerrit error when Change-Id in commit messages are missing

I set up a branch in the remote repository and made some commits on that branch. Now I want to merge the remote branch to the remote master.

Basically follows are my operations:

  1. checkout branch
  2. checkout master
  3. merge branch and fix merging errors
  4. commit
  5. push origin HEAD:refs/for/master

But get error messages on the 5th step:

remote: Resolving deltas:   0% (0/12)

remote: ERROR: missing Change-Id in commit message
...

remote: Change-Id: I55862204ef71f69bc88c79fe2259f7cb8365699a

To ssh://[email protected]:29418/hello_git
 ! [remote rejected] HEAD -> refs/for/master (missing Change-Id in commit message)
like image 998
Pan Ruochen Avatar asked Jan 13 '12 03:01

Pan Ruochen


People also ask

How do I change my ID on Gerrit?

Updating an old commit If a commit was created before the availability of Change-Id support, or was created in a Git repository that was missing the 'commit-msg' hook, simply copy the “Change-Id: I… ​” line from the first line of the Description section of the change and amend it to the bottom of the commit message.

How do I change commit message in Gerrit?

You can modifiy the commit message from gerrit UI directly. Just open the commit message on gerrit and click on the edit button next to patch-sets on the above. Do any change and then save it. You will need to submit you new commit message afterwards, appearing just above the owner section on the commit page.

How do you squash the commits with the same change-ID?

To squash the commits, use git rebase -i to do an interactive rebase. For the example above where the last two commits have the same Change-Id, this means an interactive rebase for the last two commits should be done. For further details about the git rebase command please check the Git documentation for rebase.

How do I change commit message?

On the command line, navigate to the repository that contains the commit you want to amend. Type git commit --amend and press Enter. In your text editor, edit the commit message, and save the commit.


3 Answers

Try this:

git commit --amend

Then copy and paste the Change-Id: I55862204ef71f69bc88c79fe2259f7cb8365699a at the end of the file.

Save it and push it again!

like image 24
vailaya shreesha Avatar answered Oct 17 '22 15:10

vailaya shreesha


Check if your commits have Change-Id: ... in their descriptions. Every commit should have them.

If no, use git rebase -i to reword the commit messages and add proper Change-Ids (usually this is a SHA1 of the first version of the reviewed commit).

For the future, you should install commit hook, which automatically adds the required Change-Id.

Execute scp -p -P 29418 username@your_gerrit_address:hooks/commit-msg .git/hooks/ in the repository directory or download them from http://your_gerrit_address/tools/hooks/commit-msg and copy to .git/hooks

Now git commit --amend --no-edit inserts the line.

like image 187
Rafał Rawicki Avatar answered Oct 17 '22 16:10

Rafał Rawicki


If you need to add Change-Id to multiple commits, you can download the hook from your Gerrit server and run these commands to add the Change-Ids to all commits that need them at once. The example below fixes all commits on your current branch that have not yet been pushed to the upstream branch.

tmp=$(mktemp)
hook=$(readlink -f $(git rev-parse --git-dir))/hooks/commit-msg
git filter-branch -f --msg-filter "cat > $tmp; \"$hook\" $tmp; cat $tmp" @{u}..HEAD
like image 7
Matt Cowell Avatar answered Oct 17 '22 16:10

Matt Cowell