Search code examples
linuxgitgit-diff

how to generate a patch which is a totally new file?


When using git, I have a totally new file.

git diff

will show nothing.

I need to generate the diff content for other people.

ex:

git diff > 001.patch

How to let the 001.patch contains the new file's content?


Solution

  • A totally new file isn't tracked, and therefore wouldn't be shown by git diff. I'd stage it by using git add ./path/to/my/new/file.txt, along with git adding any other changes you may have, and then use git diff --cached.