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

Re: Bug: fatal: patch fragment without header at line

From
Jeff King <peff@peff.net>
Date
Jul 17, 2012, 04:21 UTC
Message-ID
<20120717042137.GE20945@sigill.intra.peff.net>
In-Reply-To
<CAK5QfLMs6CMCTtZ3woQfMim1ssYLKEURAMv8+FgqrKJ7otNcnw@mail.gmail.com>
On Mon, Jul 16, 2012 at 07:06:51PM +0530, tuxdna wrote:
Show 14 quoted lines
> Git version: git-1.7.7.6-1.fc16.x86_64
> 
> I am getting an error with a patch that I am applying to a git repository.
> I have created a test case for this issue that I am facing.
> 
> $ git apply --check 0001-modified-README.patch
> fatal: patch fragment without header at line 7: @@ -635,9 +635,7 @@
> some_function()
> 
> Clearly line 7 appears to be a patch but it isn't. It is the part of
> email body or the patch context.
> To my understanding, the patch should always be identified whenever
> the patch block starts
> with a "diff --git", which is line 21 as below:

It is identified properly when you use "git am" to apply your patch. It will use "git mailinfo" to split on the "---" and feed only the bottom half to "git apply". But as a low-level tool, "git apply" looks for a patch immediately, and does not know anything about the "---" line. It is correct to diagnose a possibly broken patch.

> Apart from changing the patch itself, how else can I work-around this problem?

Run "git am 0001-modified-README.patch" to parse it correctly. If for some reason you really do not want to make a commit (e.g., you are going to squash-apply a bunch of patches together), then either:

  1. Don't use format-patch to generate the patch. Use "git diff-tree",
     which will omit the commit message (which "git apply" would just
     inore anyway).
  2. Use "git mailinfo" to split the patch out of the email format
     generated by format-patch, and then "git apply" the result.
-Peff
Previous: Junio C Hamano
Message 3 of 3 in “Bug: fatal: patch fragment without header at line”
  1. tuxdnaJul 16, 2012
  2. Junio C HamanoJul 16, 2012
  3. Jeff KingJul 17, 2012

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.