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:
- checkout branch
- checkout master
- merge branch and fix merging errors
- commit
- 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://prc@test.gerrit.xxx.com:29418/hello_git
! [remote rejected] HEAD -> refs/for/master (missing Change-Id in commit message)
You need to follow below 2 steps instructions:
[Issue] remote: Hint: To automatically insert Change-Id, install the hook:
1)
gitdir=$(git rev-parse --git-dir);
2)
scp -p -P 29418 <username>@gerrit.xyz.se:hooks/commit-msg ${gitdir}/hooks/
normally $gitdir = ".git". You need to update the username and the Gerrit link.
You might be an admin doing a one-off push directly into
refs/changes/<change_number>
.For example, once a commit without Change-Id landed into Subversion, you pull it out of Subversion using git-svn, and you'd like to archive it as a Gerrit patchset into a Gerrit change.
If so, you can go to project settings page (http://[installation-path]/#/admin/projects/[project-id]) and temporarily change "Require Change-Id in commit message" value to False.
Don't forget to afterwards change it back to Inherit or True!
1) gitdir=$(git rev-parse --git-dir);
a) I don't know how to execute step 1 in windows so skipped it and used hardcoded path in
step 2 scp -p -P 29418 <username>@gerrit.xyz.se:hooks/commit-msg .git/hooks/
b) In case you get below error, manually create "hooks" directory in .git folder
c) if you have submodule let's say "XX" then you need to repeat step 2 there as well and this time replace ${gitdir} with that submodules path
d) In case scp is not recognized by windows give full path of scp
e) .git folder is present in your project repo and it's hidden folder
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 fromhttp://your_gerrit_address/tools/hooks/commit-msg
and copy to .git/hooksI got this error message too.
and what makes me think it is useful to give an answer here is that the answer from @Rafał Rawicki is a good solution in some cases but not for all circumstances. example that i met:
solution:
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.