Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gerrit recreating change-ids

Tags:

git

gerrit

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.

like image 367
Frank Sposaro Avatar asked Oct 25 '11 18:10

Frank Sposaro


People also ask

How do I create a new Gerrit change-ID?

Creating a new commitWhen you exit the editor, git will call the hook, which will automatically generate and insert a unique Change-Id line. You can inspect the modified message after the commit is complete by executing git show .

How do I amend changes in Gerrit?

From the Gerrit Code Review dashboard, select Browse > Repositories. Under Repository Commands, click Create Change. In the Create Change window, enter the following information: Select branch for new change: Specify the destination branch of the change.

What is Gerrit change-ID?

A change represents a single commit under review. Each change is identified by a Change-Id. Multiple git commits can share the same Change-Id, allowing you to update a change as you receive feedback through the code review process. In Gerrit, commits that share the same Change-Id are referred to as patch sets.

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.


1 Answers

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.

like image 54
Tomasz Wysocki Avatar answered Nov 15 '22 19:11

Tomasz Wysocki