1

For me Git is creating error every single time when ever i am trying to push the code .With following command

git push origin HEAD:refs/for/master

So for temporary fix i have to use below command

 git commit --amend

then manually add the Change-Id as followed to this another Stackoverflow question,So this will allow to push the code.

But again if i will try to push any other code next time it will fail with the same error(Please have a look below)

Counting objects: 63, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (39/39), done.
Writing objects: 100% (63/63), 5.94 KiB | 0 bytes/s, done.
Total 63 (delta 22), reused 28 (delta 4)
remote: Resolving deltas: 100% (22/22)
remote: Processing changes: refs: 1, done
remote: ERROR: [2a1ab5e] missing Change-Id in commit message footer
remote:
remote: Hint: To automatically insert Change-Id, install the hook:
remote:   gitdir=$(git rev-parse --git-dir); scp -p -P 29418 subodhjoshi@gerrit.ext.net.google.com:hooks/commit-msg ${gitdir}/hooks/
remote: And then amend the commit:
remote:   git commit --amend
remote:
To ssh://gerrit.ext.net.google.com:29418/projectname/framework
 ! [remote rejected]   HEAD -> refs/for/master ([2a1ab5e] missing Change-Id in commit message footer)
error: failed to push some refs to 'ssh://gerrit.ext.net.google.com:29418/projectname/framework'

So i tried to add a hook like this

$ scp -p -P 29418 subodhjoshi@gerrit.ext.net.google.com:hooks/commit-msg  C:/GIT_Code_Base/unified-inventory/framework/framework/.git/hooks/
commit-msg                                    100% 4780    23.7KB/s   00:00

and again tried to push but end up with same error.

My question is that why every single time i have to add change-Id before the commit ? What is the permanent fix for this issue?

phd
  • 82,685
  • 13
  • 120
  • 165
Subodh Joshi
  • 12,717
  • 29
  • 108
  • 202
  • Just curious, what's `HEAD:refs/for/master`, I usually just `git push origin master` – Loi Nguyen Huynh Dec 24 '19 at 15:08
  • @LoiNguyenHuynh we are using this `HEAD:refs/for/master` . – Subodh Joshi Dec 24 '19 at 15:12
  • I know, just curious what's it different with just `master`. I see people usually use `master`. – Loi Nguyen Huynh Dec 24 '19 at 15:14
  • 1
    @LoiNguyenHuynh These are Gerrit's URLs. – phd Dec 24 '19 at 15:16
  • 1
    @LoiNguyenHuynh We are using Gerrit with Git so any code push need approval to merge .so actually we are using image . – Subodh Joshi Dec 24 '19 at 15:16
  • Does this answer your question? [Gerrit error when Change-Id in commit messages are missing](https://stackoverflow.com/questions/8845658/gerrit-error-when-change-id-in-commit-messages-are-missing) – phd Dec 24 '19 at 15:17
  • https://stackoverflow.com/search?q=%5Bgerrit%5D+missing+Change-Id+in+commit+message+footer – phd Dec 24 '19 at 15:17
  • 1
    You need `commit-msg` from Gerrit. After you set it up do rebase to add `Change-Id` to existing commits. – phd Dec 24 '19 at 15:17
  • @phd Same link i added i my question as well,its not working in my case.Every Single commit need a `Change-Id` which is a headache for me ,same issue not coming to other 159 developers of my team.I did rebase 2-3 times and try again but i end up with same issue again. – Subodh Joshi Dec 24 '19 at 15:19
  • No headache; `commit-msg` adds `Change-Id` automatically and you don't need to do anything manually. You just need to copy it to `.git/hooks` and make executable. – phd Dec 24 '19 at 15:27
  • @phd you mean i have to execute this command `scp -p -P 29418 subodhjoshi@gerrit.ext.net.google.com:hooks/commit-msg C:/GIT_Code_Base/unified-inventory/framework/framework/.git/hooks/` again and `commit-msg` will replace with the some message? – Subodh Joshi Dec 24 '19 at 15:29
  • No, `scp` only copies the file. Then you have to verify it's executable and run `git rebase -i` to add `Change-Id` to commits that don;t have it now. – phd Dec 24 '19 at 15:32

1 Answers1

2

The Gerrit message is self explanatory, just do the following:

1) Go to the local repository directory:

cd LOCAL-REPO-DIR

2) Install the commit-msg hook:

gitdir=$(git rev-parse --git-dir); scp -p -P 29418 subodhjoshi@gerrit.ext.net.google.com:hooks/commit-msg ${gitdir}/hooks/

3) Fix your current commit:

git commit --amend

Note 1: In step 3, you don't need to change anything in the commit, just run the "git commit --amend" command, save the commit message and exit. The Change-Id will be added automatically by the commit-msg hook. Execute "git log" to check that Change-Id was correctly added.

Note 2: From now on, everytime you create a commit the Change-Id will be added automatically by the commit-msg hook.