简体   繁体   中英

Is there a way to make 'git cherry-pick -x' only record the most recent 'cherry-picked from' message?

When we use git cherry-pick -x <commit> , it records the source commit in the commit message as follows (cherry picked from commit 5f2662a29efaa91af6b356df2d5d1df69017cac1)

I have a bunch of commits which I need to keep migrating from one base branch to the next. If I use cherry-pick -x, it keeps adding the latest source commit to the message.

Suppose I have used cherry-pick -x to migrate the commit twice, my commit message looks like below:

commit fb3bead084edc27267219d9a8e088ac613159f69 (my-new-branch)
Author: ----
Date:   Thu Feb 17 15:29:15 2022 +0530

    Test commit 1

    (cherry picked from commit 5f2662a29efaa91af6b356df2d5d1df69017cac1)
    (cherry picked from commit 11c6ca55b06cbf333fff9a3cfd50c6617adc2e77)

Is there way make cherry-pick -x overwrite the 'cherry picked from' message if there is already one? I want to record only the most recent source commit.

No, that's the way it works.

But you have alternatives:

  1. You can use the --edit option (thanks @joanis for pointing out in the comments)

With this option, git cherry-pick will let you edit the commit message prior to committing.

  1. You can use the --no-commit option and change the message before actually committing it.

Usually the command automatically creates a sequence of commits. This flag applies the changes necessary to cherry-pick each named commit to your working tree and the index, without making any commit. In addition, when this option is used, your index does not have to match the HEAD commit. The cherry-pick is done against the beginning state of your index.

This is useful when cherry-picking more than one commits' effect to your index in a row.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM