Re: git-am applies commit message diffs
From: Jeff King <hidden>
Date: 2026-02-06 10:08:39
On Fri, Feb 06, 2026 at 10:48:29AM +0100, Florian Weimer wrote:
quoted
On Fri, Feb 06, 2026 at 09:59:31AM +0100, Florian Weimer wrote:quoted
Isn't the format-patch output already unambiguous because the sequence of diffs is preceeded by the non-diff statistics section, and only then the commit message follows? It's just not possible to process this correctly in one pass because only at the end of the input, you know that you have just seen the to-be-applied diffs.That diffstat is optional, and not parsed by the receiving format-patch at all. Keep in mind that in the world for which it was originally designed, people were not necessarily using Git to generate their emails. They could be patches emailed by random folks using "diff" themselves.Is the git am format that flexible in practice? I often have trouble applying patches with git am that were created with git format-patch and have to resort to plain old patch instead. As a user, I definitely get the impression that it's not a type of tool that gets a patch out of an email message, no matter what the cost.
I'm sure there are corner cases it doesn't handle, but it will take input like this: git am <<\EOF From: Jeff King <redacted> Date: Fri Feb 6 03:42:12 2026 -0500 Subject: my cool patch this fixes some stuff diff -Nru old/file new/file
--- old/file 2026-02-06 04:58:56.148348259 -0500
+++ new/file 2026-02-06 04:58:59.432360938 -0500@@ -1 +1 @@ -base +changed
EOF and happily produce the commit you'd expect. I generated the diff there with GNU diff, and typed the rest. Likewise for this version with attachments, which I generated with mutt: git am <<\EOF Date: Fri, 6 Feb 2026 05:03:31 -0500 From: Jeff King <redacted> To: Jeff King <redacted> Subject: my cool patch MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="tveeCB9LAhLXuhMJ" Content-Disposition: inline --tveeCB9LAhLXuhMJ Content-Type: text/plain; charset=utf-8 Content-Disposition: inline see the attached patch, which does blah blah blah --tveeCB9LAhLXuhMJ Content-Type: text/plain; charset=utf-8 Content-Disposition: attachment; filename=patch diff -Nru old/file new/file
--- old/file 2026-02-06 04:58:56.148348259 -0500
+++ new/file 2026-02-06 04:58:59.432360938 -0500@@ -1 +1 @@ -base +changed --tveeCB9LAhLXuhMJ--
EOF I expect that Linus saw a lot of this kind of stuff in the early days. I'd guess it's pretty rare now, but I won't be surprised if there are some die-hards generating kernel patches with who-knows-what. ;) -Peff