git diff doesn't print an error for bad filenames

Viewed 30

Let's say that I issue the following command:

git diff hash1 hash2 -- MyFile.java

If the versions of the file in the two hashes are identical, then git returns no output. That seems reasonable and expected. However, if instead I pass a bad filename like this:

git diff hash1 hash2 -- MyFile.javaaaa

instead of getting an error, git again returns no output. I know that this behavior isn't universal; there are other git commands that do complain about a bad filename. But that's not happening here. And it's a real problem, because I can't differentiate between the case where there really is no difference and the case where I've just fat fingered the filename.

This can't be right. What am I missing? Is there some setting I can change?

1 Answers

In git diff's document, <path> "are used to limit the diff to the named paths", which sounds like that it acted like a filename filter, rather than a filename specifier.

That is, if you enter a filename that this file not exists, you will filter out all files, remaining nothing in the output.

Related