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

let git-diff allow patch to delete empty files?

From
SLSam Liddicott <sam@liddicott.com>
Date
Nov 5, 2008, 10:40 UTC
Message-ID
<49118FEE.30408@liddicott.com>

In some cases "patch" cannot apply diff's generated using git-diff, I've had a "git diff" output look like this when an empty file was removed as the only change:

diff --git a/source3/include/dcerpc.h b/source3/include/dcerpc.h
deleted file mode 100644
index e69de29..0000000

which patch rejected, saying:
patch: **** Only garbage was found in the patch input.

There is a ghastly diff notation recognized by patch, using the magic
date 1970-01-01 01:00:00.000000000 to signify deletion which git-diff
properly uses for non-empty files.

Empty files are a different matter because there is no unified diff that
can represent deletion of an empty file because patch doesn't like
unified diff's with no context.

However this equivalent pair works by making the file non-empty and then
deleting it.

diff -Nru 1/here 2/here
--- 1/here    2008-11-05 09:43:55.000000000 +0000
+++ 2/here    2008-11-05 09:43:58.000000000 +0000
@@ -0,0 +1 @@
+
diff -Nru 1/here 2/here
--- 1/here    2008-11-05 09:37:23.000000000 +0000
+++ 2/here    1970-01-01 01:00:00.000000000 +0100
@@ -1 +0,0 @@
-


In considering this filthy hack we should recognize that currently :

* patch will choke on certain "git diff" output. If patch's exit code is
checked as part of a loop of patches, then the patch procedure will
fail. This happened to me
* if delete-empty-file is one action in a larger patch file it will do
nothing - which can be worse if the "existence" of a file affects the
build system.

This filthy hack fixes both problems.

Sam
Next: Sam Liddicott
Message 1 of 4 in “let git-diff allow patch to delete empty files?”
  1. Sam LiddicottNov 5, 2008
  2. Sam LiddicottNov 5, 2008
  3. Nanako ShiraishiNov 5, 2008
  4. Sam LiddicottNov 6, 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.