Question

when running git format-patch, the intent is to create an email representation of the code you wrote. So far so good. I'm no email expert, but it seems to me that the first line of this format-patch output isn't in a standard email header format...

From de8d128fb520416e0b029c913b3a5ce900d0320c Mon Sep 17 00:00:00 2001
Message-Id: 
From: Christopher Harvey 
Date: Wed, 3 Apr 2013 10:17:52 -0400
Subject: [PATCH 0/3] *** SUBJECT HERE ***
To: Christopher Harvey 

*** BLURB HERE ***

Christopher Harvey (3):
  commit 2
  commit 3
  commit 4

 data | 3 +++
 1 file changed, 3 insertions(+)

-- 
1.7.12.4

what is From de8d128fb520416e0b029c913b3a5ce900d0320c Mon Sep 17 00:00:00 2001? what is the date for? It looks arbitrary to me, and it also prevents me from piping it to sendmail. I have to manually remove that line each time I want to send a patch.

thanks.

Was it helpful?

Solution

From git help format-patch

DISCUSSION The patch produced by git format-patch is in UNIX mailbox format, with a fixed "magic" time stamp to indicate that the file is output from format-patch rather than a real mailbox, like so:

       From 8f72bad1baf19a53459661343e21d6491c3908d3 Mon Sep 17 00:00:00 2001
       From: Tony Luck <tony.luck@intel.com>
       Date: Tue, 13 Jul 2010 11:42:54 -0700
       Subject: [PATCH] =?UTF-8?q?> > [IA64]=20Put=20ia64=20config=20files=20on=20the=20?=
        =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig=20diet?=
       MIME-Version: 1.0
       Content-Type: text/plain; charset=UTF-8
       Content-Transfer-Encoding: 8bit

OTHER TIPS

As an appendix to Fredrik's answer, here are some relevant comments by Junio Hamano:

"Mon Sep 17 00:00:00 2001" is just a fake random date to make the Unix-From line recognizable by common MUA and does not have anything to do with your commit objects. The real date is on Date: header.

I actually once tried to change it to git's birthday (Thu Apr 7 15:13:13 2005 -0700) and I recall that it turned out that some people's scripts (or perhaps MUA) were broken and cared what was before "7" ... on the Unix-From line and discarded that update.

The "From $SHA1 $magic_timestamp" line and other header lines are there to make it look like a mbox

Links: 1, 2, 3.

The output is in mbox format. You can easily strip the first line with:

git format-patch --stdout <range> | sed 1d

and then do as you please with the result.

Alternatively you can use git itself to send the email. Try:

git send-mail --smtp-server=<your server> *.patch

See GIT Send-Mail Manpage for all the options.

from wikipedia (https://en.wikipedia.org/wiki/September_17)

2001 – The New York Stock Exchange reopens for trading after the September 11 attacks, the longest closure since the Great Depression.

maybe just coincidence!

Git 2.32 (Q2 2021) actually explains pieces of the format-patch output upfront before the rest of the documentation starts referring to them.

See commit 28e29ee (24 Mar 2021) by Junio C Hamano (gitster).
(Merged by Junio C Hamano -- gitster -- in commit 5c2f7ff, 30 Mar 2021)

format-patch: give an overview of what a "patch" message is

The text says something called a "patch" is prepared one for each commit, it is suitable for e-mail submission, and "am" is the command to use it, but does not say what the "patch" really is.

The description in the page also refers to the "three-dash" line, but it is unclear what it is, unless the reader is given a more detailed overview of what the "patch" is.

Add a brief paragraph to give an overview of what the output looks like.

git format-patch now includes in its man page:

Prepare each commit with its "patch" in one "message" per commit, formatted to resemble a UNIX mailbox.

A "message" generated by the command consists of three parts:

  • A brief metadata header that begins with From <commit> with a fixed Mon Sep 17 00:00:00 2001 datestamp to help programs like "file(1)" to recognize that the file is an output from this command, fields that record the author identity, the author date, and the title of the change (taken from the first paragraph of the commit log message).

  • The second and subsequent paragraphs of the commit log message.

  • The "patch", which is the "diff -p --stat" output (see git diff) between the commit and its parent.

The log message and the patch is separated by a line with a three-dash line.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top