Is it possible to ask git diff to include untracked files in its diff output? Or is my best bet to git add the new files I've created and the existing files I've edited, and use
git diff --cached
?
Is it possible to ask git diff to include untracked files in its diff output? Or is my best bet to git add the new files I've created and the existing files I've edited, and use
git diff --cached
?
I believe you can diff against files in your index and untracked files by simply supplying the path to both files.
git diff --no-index tracked_file untracked_file
With recent git versions you can "git add -N" the file (or "--intent-to-add"), which adds a zero-length blob to the index at that location. The upshot is that your "untracked" file now becomes a modification to add all the content to this zero-length file, and that shows up in the "git diff" output.
srh@devo16:/tmp/git-example <master>$ git diff
srh@devo16:/tmp/git-example <master>$ echo "this is a new file" > new.txt
srh@devo16:/tmp/git-example <master>$ git diff
srh@devo16:/tmp/git-example <master>$ git add -N new.txt
srh@devo16:/tmp/git-example <master>$ git diff
diff --git a/new.txt b/new.txt
index e69de29..3b2aed8 100644
--- a/new.txt
+++ b/new.txt
@@ -0,0 +1 @@
+this is a new file
Another point about this is that now that the new file is a modification and the path is known to git, "git stash" will work to stash the file away too.