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

Re: Why doesn't git-apply remove empty file

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Aug 13, 2008, 23:09 UTC
Message-ID
<alpine.LFD.1.10.0808131602200.3462@nehalem.linux-foundation.org>
In-Reply-To
<48A357BA.8060003@lsrfire.ath.cx>
On Wed, 13 Aug 2008, René Scharfe wrote:
> 
> I bet you are using GNU patch.  It removes files that are empty after
> patching and you need to specify --posix to make it keep empty files.

GNU patch' behavior wrt empty files is a bit more complex than that. It's true that you can disable it all with the POSIX mode (not that anybody ever does), but it's not an unconditional removal, I think.

It does look at the date of the destination if there is one, ie according to the man-page:

      "You can create a file by sending out a diff that compares /dev/null  or
       an empty file dated the Epoch (1970-01-01 00:00:00 UTC) to the file you
       want to create.  This only works if the file you want to create doesn’t
       exist  already  in  the target directory.  Conversely, you can remove a
       file by sending out a context diff that compares the file to be deleted
       with  an  empty  file dated the Epoch.  The file will be removed unless
       patch is conforming to POSIX and the -E or --remove-empty-files  option
       is  not  given.  An easy way to generate patches that create and remove
       files is to use GNU diff’s -N or --new-file option."

and no, git never did that file date thing, so git acts differently from GNU patch in this thing (as in so many others, for that matter).

I don't think it would necessarily be wrong to try to emulate GNU patch for the case where git is guessing at removal, though (ie for the "traditional diff" case - for a "git diff", the removal question is unambiguous thanks to the git extensions, of course).

That said, I'm also not personally very motivated to add yet another odd GNU patch behavior quirk. Especially as we very much try to avoid parsing that insane and not-well-specified date format anyway, and just ignore it. But if somebody sends out a tested patch to add such logic, I wouldn't think it _wrong_ either.

			Linus
Previous: René ScharfeNext: Francis Moreau
Message 5 of 14 in “Why doesn't git-apply remove empty file”
  1. Francis MoreauAug 12, 2008
  2. Junio C HamanoAug 13, 2008
  3. Francis MoreauAug 13, 2008
  4. René ScharfeAug 13, 2008
  5. Linus TorvaldsAug 13, 2008
  6. Francis MoreauAug 14, 2008
  7. Linus TorvaldsAug 14, 2008
  8. Linus TorvaldsAug 14, 2008
  9. Stephan BeyerAug 14, 2008
  10. Jeff KingAug 14, 2008
  11. Stephan BeyerAug 14, 2008
  12. Jeff KingAug 15, 2008
  13. Linus TorvaldsAug 15, 2008
  14. Francis MoreauAug 14, 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.