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:
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)
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.
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.
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.
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.
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!
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With