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

Re: git apply behaves differently from patch(1)

From
Johannes Sixt <j.sixt@viscovery.net>
Date
Jan 17, 2008, 08:11 UTC
Message-ID
<478F0DC0.9030107@viscovery.net>
In-Reply-To
<200801162358.48723.zander@kde.org>
Thomas Zander schrieb:
Show 5 quoted lines
> In the following usecase git apply (git version 1.5.4.rc3.15.g785f9) 
> doesn't do what I expect it should do. I expect it to do the same as 
> patch does in the same situation.
> 
> To reproduce;
[... hand-edit a patch without context ...]
Show 10 quoted lines
> What I expect (and what I get if I replace git apply with a 'patch -R -p1 
> < mypatch') is that the diff shows line "2" is still missing.
> 
> What I get instead is that "2" is missing but also that "10" moved 2 lines 
> up.
> I conclude that git somehow doesn't like the patch to be removed, while 
> patch(1) has no problem with that.
> 
> I hope you agree its a bug and fix it in an upcoming version, it would be 
> great if I can avoid using patch(1) or worse.

It's not exactly a bug. The behavior of zero-context patches is simply not well-defined. You have just been lucky that patch worked in the way that you expected. Don't use zero-context patches.

That said git-apply can certainly be modified to behave like patch in this case. I tried, but gave up - it's too much code that is new to me. :(

-- Hannes
Previous: Thomas ZanderNext: Linus Torvalds
Message 2 of 3 in “git apply behaves differently from patch(1)”
  1. Thomas ZanderJan 16, 2008
  2. Johannes SixtJan 17, 2008
  3. Linus TorvaldsJan 17, 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.