Git补丁文件作为Outlook邮件附件被修改。

5
我希望通过Outlook发送由git format-patch命令生成的.patch文件(在我的工作环境中必须使用Outlook,不需要建议我使用其他方式)。目的只是为了让同事审查我的代码,在将更改推送到主存储库之前。当我将补丁文件作为附件发送时,会在我的补丁文件开头插入一个>字符。

例如:

>From 7ff70407d24338e928fafcd89115f9844c21691b Mon Sep 17 00:00:00 2001
From: user <user@company.com>
Date: Wed, 21 Mar 2012 09:55:17 -0400
Subject: [PATCH] Blahblah...

这使得git am无法在我的同事系统上应用补丁。
我不知道(也不知道如何找出)如何验证修改发生在发送端还是接收端。
有人知道是什么原因吗?是否有一些Outlook中的设置我应该修改以避免这种情况?
提前致谢。
3个回答

3
这与一个名为“mbox”的旧Unix邮箱文件格式有关:mbox

mboxo and mboxrd locate the message start by scanning for From lines that are typically found in the e-mail message header. If a "From " string occurs at the beginning of a line in either the headers or the body of a message (unlikely for the former for correctly formatted messages, but likely for the latter), the e-mail message must be modified before the message is stored in an mbox mailbox file or the line will be taken as a message boundary. This is typically done by prepending a greater-than sign:

>From my point of view...

在你的情况下,我们无法确定你的邮件系统中哪个组件可能会添加这个 >

对于 Git 的使用,你可以删除 >,或者直接删除整行(因为电子邮件消息头对 Git 不相关)。


1
当我将补丁文件作为附件发送时,会在我的补丁文件开头插入一个>字符。
现在,通过Git 2.40(2023年第一季度),可以转义那些“>From”行了。 "git format-patch" man 学会了在将补丁发送到标准输出流时尊重format.mboxrd
我在“为什么mail命令会向电子邮件添加额外的字符(“>”)?”中介绍了mboxrd
查看 提交 4810946(2022年12月22日),作者为 Eric Wong(ele828
(由Junio C Hamano -- gitster --提交e83d57e中合并,日期为2023年1月2日)

format-patch:支持使用--stdout选项的format.mboxrd

签名作者:Eric Wong

“mboxrd” 是一个更健壮的输出格式,当与“--stdout”一起使用时需要更多的曝光。引入这个配置开关让用户选择更健壮的格式来处理他们所有的“--stdout”用途。依赖于“--pretty=mboxrd”并在 git format-patch(man) 文档中包含所有的“pretty-formats.txt”可能会令用户感到困惑。此外,这个设置在多次调用中非常有用。因此,引入一个名为“format.mboxrd”的布尔配置开关,当(且仅当)使用“--stdout”时,将默认的“--pretty=email”格式更改为“--pretty=mboxrd”。

git config现在在其手册页面中包含:

format.mboxrd

一个布尔值,当使用--stdout时启用健壮的“mboxrd”格式以转义“^>+From”行。

示例:

git -c format.mboxrd format-patch --stdout -1 $C~1..$C >patch 

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接