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

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

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 16, 2012, 17:19 UTC
Message-ID
<7vy5mj39ow.fsf@alter.siamese.dyndns.org>
In-Reply-To
<CAK5QfLMs6CMCTtZ3woQfMim1ssYLKEURAMv8+FgqrKJ7otNcnw@mail.gmail.com>
tuxdna <tuxdna@gmail.com> writes:
Show 11 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.

Yes, but the error detection needs to stay for a more common case in which the user corrupted the patch by breaking or removing the diff header.

If you want to quote a patch fragment in your log message, it is common to indent the part (without removing the "diff" header) which also has the benefit of making it stand out in the textual description, e.g. here is a sample patch fragment

    diff --git a/README b/README
    index ce01362..d294257 100644
    --- a/README
    +++ b/README
    @@ -1 +1,2 @@
     hello
    +this is a readme

and here comes a paragraph in the log message that can be made more understandable by having such a patch fragment.

Previous: tuxdnaNext: Jeff King
Message 2 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.