简体   繁体   English

有没有办法让“git cherry-pick -x”只记录最近的“cherry-picked from”消息?

[英]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)当我们使用git cherry-pick -x <commit>时,它在提交消息中记录源提交如下(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.如果我使用 cherry-pick -x,它会不断将最新的源代码提交添加到消息中。

Suppose I have used cherry-pick -x to migrate the commit twice, my commit message looks like below:假设我已经使用 cherry-pick -x 迁移了两次提交,我的提交消息如下所示:

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?如果已经有消息,是否有办法让 cherry-pick -x 覆盖“cherry picked from”消息? 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)您可以使用--edit选项(感谢@joanis 在评论中指出)

With this option, git cherry-pick will let you edit the commit message prior to committing.使用此选项,git cherry-pick 将允许您在提交之前编辑提交消息。

  1. You can use the --no-commit option and change the message before actually committing it.您可以使用--no-commit选项并在实际提交之前更改消息。

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.此外,使用此选项时,您的索引不必与 HEAD 提交匹配。 The cherry-pick is done against the beginning state of your index. cherry-pick 是针对索引的开头 state 完成的。

This is useful when cherry-picking more than one commits' effect to your index in a row.当连续挑选多个提交对索引产生影响时,这很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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