16

What does the --- /dev/null signify in by git show commit output?

This is an addition of a new file, so I assume it's saying that nothing was removed, but why the reference to /dev/null?

$ git show a395a
commit a395a7bb4abcc606022ac14a07794b2d3c18bd5b
Author: David Banks <BanksySan@googlemail.com>
Date:   Sun Apr 12 17:41:08 2015 +0100

    My first commit.

diff --git a/test.txt b/test.txt
new file mode 100644
index 0000000..e965047
--- /dev/null
+++ b/test.txt
@@ -0,0 +1 @@
+Hello
BanksySan
  • 27,362
  • 33
  • 117
  • 216

2 Answers2

21

It means that because test.txt is a new file, in the diff shown, it was compared to "nothing"; the "file" /dev/null.

asjo
  • 3,084
  • 2
  • 26
  • 20
  • OK, go it really does a full diff on a new file, it just diffs it against `/dev/null`. Cool, thanks. – BanksySan Apr 12 '15 at 17:01
  • To be complete, we must add that "/dev/null" is a "real" file in the Unix filetree. It is used using `|` in the command line and shell to throw away a content generated that we don't need anymore... – Philippe Apr 12 '15 at 18:42
11

You can find that convention (diff against "no file") from the very beginning of Git itself.

The goal was to be more like the cg-patch Linux tool, which apply a patch from a file, input, or a commit.

See commit 2f97813, Git 0.99, Apr. 2005:

Make diff-cache and friends output more cg-patch friendly.

This changes the way the default arguments to diff are built when diff-cache and friends are invoked with -p and there is no GIT_EXTERNAL_DIFF environment variable.
It attempts to be more cg-patch friendly by:

  • Showing diffs against /dev/null to denote added or removed files;
  • Showing file modes for existing files as a comment after the diff label.
Gaurang Tandon
  • 6,504
  • 11
  • 47
  • 84
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250