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

git diff --numstat notices empty file creation, while --stat does not

From
VSVishvajit Singh <vishvajitsingh@gmail.com>
Date
Apr 23, 2010, 04:17 UTC
Message-ID
<k2r520868e81004222117nedbd7a3flb94bf7bef65d9c68@mail.gmail.com>

I noticed that, in the case of two trees that differ in the creation or deletion of an empty file, git diff --numstat provides information about the empty file, whereas git diff --stat does not.

$ git --version
git version 1.6.1.2
$ git status
# On branch master
nothing to commit (working directory clean)
$ touch x.txt
$ git add x.txt
$ git commit -m 'add x.txt'
[master]: created 62f3c25: "add x.txt"
 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 x.txt
$ git diff --stat HEAD^ HEAD
 0 files changed, 0 insertions(+), 0 deletions(-)
$ git diff --numstat HEAD^ HEAD
0       0       x.txt

This behaviour surprised me as I had been using diff --stat to get an overview of the current differences between my working branch and the master, and I had created a temporary to-do-list file in that branch which I had subsequently emptied. In closing that branch, I might have inadvertently merged the empty file into the master if I had not remembered it was there. (I will use --numstat instead now.)

Is this small difference in behaviour between the two intentional?

Thanks, Vishvajit Singh

Message 1 of 1 in “git diff --numstat notices empty file creation, while --stat does not”
  1. Vishvajit SinghApr 23, 2010

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.