That is because git diff
only lists changes of files that are part of the repository, and your newly created file is not.
The easiest solution is to add the file to the index:
$ git add ABC.txt
And then use the --cached
option when creating the patch:
$ git diff --cached > mypatch.diff
However if the error happens when you apply the diff, it may be caused because the file does not exist in the target branch, so git
does not know where to apply those changes.
You can see if the diff file contains changes to an formerly existing file, or a newly created file, by looking at the chunk header:
If you see:
--- a/ABC.txt
+++ b/ABC.txt
Then there are changes to an existing file. Applying this patch will not create a new file from void.
But if you see:
--- /dev/null
+++ b/ABC.txt
Then it is a newly created file and applying this patch will create a new file with these contents.