Git cherry-pick: how to regenerate change id?
Asked Answered
M

4

6

We use Git together with Gerrit, and commit hook is used to generate change id for Gerrit. Now question is when cherry-picking commits, the commit hook is not triggered, hence same change id may exist for different commits in different branch. Any quick win to make change id being regenerated during cherry-picking?

Thanks.

Manufactory answered 30/4, 2014 at 10:13 Comment(0)
P
3

If you are using a recent enough version of Gerrit, it is actually desired to reuse the same Change-Id when cherry picking a commit to a different branch. This is an effective method to track which branches contain a bug fix, and it works well for us at $DAYJOB.

Earlier versions of Gerrit had issues with duplicate change-ids, but this concept of duplicate change-ids on different branches has been supported for quite some time now.

Poock answered 30/4, 2014 at 14:24 Comment(3)
Which version of Gerrit are you talking about? And how would that work for changes that have been closed?Zehe
I'm not sure, this was probably changed around the 2.2-2.4 range. You'd have to dig through the release notes to find the exact change. If the change IDs match but they are on different branches, Gerrit just creates a new change page for each commit. One will be merged and the other in review. The nice part of this workflow is if you search for the change id, Gerrit will show all the branches which contain it.Poock
My Gerrit is 2.7. The issue is if the change has been closed before cherry-picking, the cherry-picked change will be rejected by Gerrit. Not sure whether it is a configuration issue of Gerrit or not.Manufactory
A
1

Just use git commit --amend on cherry-picked commit and remove 'Change-Id:' line from commit message. If a proper hook is installed (likely it is) then a new Change-Id will be generated.

Album answered 30/4, 2014 at 10:14 Comment(0)
T
1

They don't need to be different, gerrit allows each change-id to exist once on each branch so it's fine to have the same on each branch.

Tague answered 30/4, 2014 at 14:26 Comment(0)
N
1

if you want to cherry-pick a closed review, then need generate a new change id, pls: git cherry-pick --> git commit --amend,remove the change-id line --->git push, it will create new change id.

Nuptials answered 13/7, 2017 at 3:38 Comment(1)
Hi ! It would be better if you checkout Answering Questions Format for future endeavor at Stack overflow. -Thank youWreckful

© 2022 - 2024 — McMap. All rights reserved.