Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the significance of /dev/null in a git show commit?

Tags:

git

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 <[email protected]>
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
like image 578
BanksySan Avatar asked Apr 12 '15 16:04

BanksySan


2 Answers

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

like image 110
asjo Avatar answered Nov 15 '22 09:11

asjo


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.
like image 42
VonC Avatar answered Nov 15 '22 09:11

VonC