gitdiffgit-index

diff does not contain new files


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.


Solution

  • 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