git/list[1] front-page[2] threads[3] people[4] search[5] about
 

git-diff/git-format-patch safe for GNU (or POSIX) patch?

From
Flavio Poletti <flavio@polettix.it>
Date
Jun 26, 2008, 10:27 UTC
Message-ID
<58230.213.203.159.164.1214476059.squirrel@upmail.polettix.it>
Hi,
   I had to dig a problem in Glib ("base" library for GTK) in Debian Etch
recently and I decided to manage changes/diffs with git. It's just so
easy to use and avoids all the usual copy-the-tree-then-diff that I
used before.

When I was happy with the modifications, I used git-format-patch to produce the message and the patch to send. I then saw that the format is a little different with respect to what diff -u produces; in particular, I noticed that there was an added line between the "diff --git..." line and the one stating the "origin" file:

                   diff --git a/glib/gstrfuncs.c b/glib/gstrfuncs.c
*** this one ***   index 61d11ed..7786f10 100644
                   --- a/glib/gstrfuncs.c
                   +++ b/glib/gstrfuncs.c

Moreover, each chunk's header contained added stuff, like the "g_ascii_strtoll..." stuff in the following example line:

    @@ -813,6 +813,8 @@ g_ascii_strtoll (const gchar *nptr,

Before sending the patch, I tried to "reverse" these "deviations" from the normal diff output, but I was quite sure there was no need to do this. I then tried to use GNU patch with the unaltered message, and it seemed quite happy with all the extra stuff.

Just to be on the safe side, I tried to look for:
1. the "official" unified diff spec
2. a description of what patch is willing to consider valid input
3. some notes about how git-diff copes with patch compatibility
4. some hints to use git for working on projects that do not use any other
VCS, or for which one only wants to produce and send a quick patch
starting from a tarball.

I had no luck with the first two attempts, and a moderate luck with the third: there is more than one email from Junio C. Hamano either stating that git-diff strives to be nice with patch, or containing patches to address possible conformance issues. I was also quite unluck with the fourth attempt, even if this is surely due to my poor websurfing-fu.

Anyway, the messages from Mr. Hamano kind-of answer the question in the subject, but in a somehow "implicit" way rather than explicitly. In particular, I wonder if there is any document about how a "valid" unified diff should look like (including optional valid extensions) that was used as input and reference for git-diff development. Or had you just to figure it out from diff/patch sources?

Thank you,
   Flavio.
Next: Karl Hasselström
Message 1 of 5 in “git-diff/git-format-patch safe for GNU (or POSIX) patch?”
  1. Flavio PolettiJun 26, 2008
  2. Karl HasselströmJun 26, 2008
  3. Flavio PolettiJun 26, 2008
  4. Karl HasselströmJun 26, 2008
  5. Petr BaudisJun 26, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.