'"git diff" does nothing

I presume this is a configuration error somewhere, but I can't figure out where. Regular git commands appear to work fine, but "git diff" does nothing. To be safe, I removed external diff tools from my .gitconfig file. This was installed via MacPorts and is the lates version (1.7.2.2).

What I see is that when I run "git diff" from my workspace, it simply exits, doing nothing.

$ git --version
git version 1.7.2.2
$ git diff
$ 

If I back up one directory, out of my root workspace, typing "git diff" gives me this:

$ git diff
usage: git diff [--no-index] <path> <path>

This may be expected behavior since I'm not under a git repository.

Any ideas on what I can do to troubleshoot this?



Solution 1:[1]

Note: starting git 1.8.5 or 1.9, Q4 2013:

When the user types "git diff" outside a working tree, thinking he is inside one, the current error message that is a single-liner:

usage: git diff --no-index <path> <path>

may not be sufficient to make him realize the mistake.

Add "Not a git repository" to the error message when we fell into the "--no-index" mode without an explicit command line option to instruct us to do so.


See:

Clarify documentation for "diff --no-index".
State that when not inside a repository, --no-index is implied and two arguments are mandatory.

Clarify error message from diff-no-index to inform user that CWD is not inside a repository and thus two arguments are mandatory.

To compare two paths outside a working tree:
usage: git diff --no-index <path> <path>

Solution 2:[2]

It does nothing if your working directory is clean and there are no differences from the last update. Try editing a file and then run git diff again, and it should then show the diff.

Solution 3:[3]

If you are using it outside of a real repository or work-copy, its behaviour is identical to the GNU diff. So you need to inform the 2 directories or files to be compared. Example:

git diff old_dir new_dir.

If there is any difference between them, the output will show you, as expected.

Solution 4:[4]

Not in your case, but maybe because the file that you pass not exists

$ git difftool HEAD HEAD^ -- path/that-not-exists

nothing happen

Solution 5:[5]

This may not apply to all situations, but when I was having this issue it was because I had not added the new files to git and committed. I had mistakenly assumed the differences in the branches would automatically appear in git diff.

I would suggest to anyone stumbling upon this post to make sure they add and commit. Again, this does not apply to every situation, but it did mine and so it may others as well.

Happy coding

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 VonC
Solution 2 Jaanus
Solution 3
Solution 4 deFreitas
Solution 5 zs4