gitcherry-pick-x:详细链接而不是摘要链接

发布于 2024-10-02 03:29:36 字数 403 浏览 4 评论 0原文

给定带有消息“foo”的提交,即只有摘要部分,我会执行gitcherry-pick -x the_commit。结果是带有消息的新提交

foo
(cherry picked from commit eb42a6475d2c2e4fff7a1b626ce6e27eec21e886)
Now that's not good, because it is a two-line summary, which seems like a bug in git.

但是我怎样才能让 git 使评论看起来像下面这样而不需要手动编辑评论呢?

foo

(cherry picked from commit eb42a6475d2c2e4fff7a1b626ce6e27eec21e886)

Given a commit with the message "foo", i.e. with only a summary part, I do git cherry-pick -x the_commit. The result is a new commit with message

foo
(cherry picked from commit eb42a6475d2c2e4fff7a1b626ce6e27eec21e886)

Now that's not good, because it is a two-line summary, which seems like a bug in git.

But how can I make git make the comment look like below without editing the comment manually?

foo

(cherry picked from commit eb42a6475d2c2e4fff7a1b626ce6e27eec21e886)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤单情人 2024-10-09 03:29:36

你是对的,这似乎是一个疏忽。您可以向 git 邮件列表 发送电子邮件,看看他们的想法!不过,现在你必须自己处理。

处理这个问题的好方法是完全避免它:使原始提交消息变得良好。如果它已经是多行,并且其中有空行,则从樱桃中添加的附加行不会破坏格式。

要解决这个问题,正如您所说,鉴于cherry-picked提交有一行消息,您可以使用cherry-pick的 -e 选项。如果您使用 Vim,最坏的情况是您必须按 ggoZZ 来处理它。

或者您可以编写一个prepare-commit-msg 挂钩。您需要的只是:

#!/bin/bash
sed -i '2s/^(cherry picked/\n&' "$1"

You're right that it seems like an oversight. You could send an email to the git mailing list and see what they think! For now you'll have to handle it yourself, though.

The good way to deal with this would be to avoid it altogether: make the original commit message good. If it's already multi-line, with the blank line in there, the appended line from the cherry-pick will not screw up the format.

To work around it, given that the cherry-picked commit has a one-line message, as you say, you can use the -e option for cherry-pick. If you're using Vim, worst case you have to hit ggo<Esc>ZZ to take care of it.

Or you could write a prepare-commit-msg hook. All you should need in it is:

#!/bin/bash
sed -i '2s/^(cherry picked/\n&' "$1"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文