1

I am working on a project which uses git. Whenever I make changes, I submit a patch to the main developer who apply and commit it. Things worked nicely this far whith:

git diff > somepatch.patch

But when I create new files, The above command doesn't work. It creates a patch which doesn't contain new files that I created. I tried adding them to git like this:-

git add path/to/the/file.qml

but this also doesn't work.

Romain Valeri
  • 19,645
  • 3
  • 36
  • 61
LightSith
  • 795
  • 12
  • 27

1 Answers1

4

If you already added your changes to the repo, they won't appear in the git diff output unless you use the --staged parameter to ask for changes already added to index.

git diff --staged > your.patch

So if you have a mix of added and non-yet-added changes, you can even the situation with

git add .

then proceed with your diff.


As a sidenote, an alternative would be to unstage everything and do a classic diff without --staged :

git reset HEAD
git diff > your.patch
Romain Valeri
  • 19,645
  • 3
  • 36
  • 61
  • now it is only showing the file that I added. Its not showing the changes that I made in other file – LightSith Dec 13 '18 at 12:52
  • @yojimbooru Add everything beforehand with `git add .` then all should be featured in `git diff --staged` output. – Romain Valeri Dec 13 '18 at 13:07
  • 1
    To add a bit to this (correct) answer, note that `git diff` without `--staged` tells Git: *compare the files stored in my index to the files stored in my work-tree*. If there is no difference, your index and work-tree match. But *with* `--staged`, you are telling Git: *compare the files stored in my `HEAD` commit to the files stored in my index*. Your work-tree is completely ignored for this `--staged` diff! There are *three* copies of every file: one in `HEAD` (frozen), one in index ("slushy": in Git format, but not quite frozen so you can change it), and one in your work-tree. – torek Dec 13 '18 at 17:26