Frank Sposaro
Frank Sposaro

Reputation: 8531

Gerrit recreating change-ids

I am using gerrit. I used the following command

$ cd .git/hooks
$ scp -P 29418 demo@localhost:hooks/commit-msg .
$ cd ../..

This adds the change-id to my commit message, however if I amend to a commit it creates a NEW change-id. So when I push back to gerrit it's not adding the patch set, it's creating a whole new review entry.

Any suggests please?

Found the answer, but stackoverflow won't let me answer my own question.

So this was a complete error on my part. When I was trying to commit git commit --amend -m "Initial Commit"

I was inlining the commit message and that was wiping away the change-Id, thus giving me a new one.

Upvotes: 18

Views: 40461

Answers (3)

drgnfr
drgnfr

Reputation: 121

  1. git commit --amend
  2. Manually delete the Change-Id line, save and close
  3. git commit --amend --no-edit

And the hook will create a new Change-Id hash, in the absence of one.

Upvotes: 8

Abhijeet
Abhijeet

Reputation: 8761

If git commit --amend or git commit --amend -m "...." doesn't help and gerrit still complains about the missing change-Id. (This happens due to network issues mostly)

This is how I got it resolved (Made sure I had the commit-msg hook applied, on parent directory of the checked-out directory reference):

  1. Stash the Changes using git stash.
  2. Used gitk & to hard rebase the change to just previous commit. enter image description here
  3. Then pull and rebase from Repo git pull --rebase.
  4. Then apply the stashed changes using git stash apply, reference. Resolve Merger Conflicts if any using git mergetool.
  5. Recommitted in the change again using git commit or git commit --amend, this generated a new change-Id
  6. Push the changes to branch on repository using git push ... command.

There is similar question around as well for reference

Upvotes: 1

Tomasz Wysocki
Tomasz Wysocki

Reputation: 11568

commit-msg hook work that way:

  1. Check if you have change-id in your commit message.
  2. If not, generates one.

If you type git commit --amend and edit commit message, you still have old change-id (it is good).

But if you type git commit --amend -m "...." you have removed change-id, so gerrit generates new one.

Rule of a thumb: Don't use --amend -m with gerrit.

Upvotes: 35

Related Questions