Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git cherry-pick: how to regenerate change id?

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.

like image 606
Skywolf Avatar asked Apr 30 '14 10:04

Skywolf


People also ask

How do I revert changes from cherry pick?

A cherry-pick is basically a commit, so if you want to undo it, you just undo the commit. Stash your current changes so you can reapply them after resetting the commit.

Does cherry picking Change commit ID?

It takes changes from a specific commit and applies them to your current branch in a new commit. As a consequence, git cherry pick does not alter your current Git history : instead it adds commits to it.

How do I change my change-ID?

Updating an old commit If a commit was created before the availability of Change-Id support, or was created in a Git repository that was missing the 'commit-msg' hook, simply copy the “Change-Id: I… ​” line from the first line of the Description section of the change and amend it to the bottom of the commit message.

How do you commit 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

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.

like image 148
Brad Avatar answered Oct 20 '22 23:10

Brad