Short answer
git diff --no-index -f file1 file2
The -f option tells Git to limit the diff to the pathspec you give it.
When you give it two file names, Git will only show the differences between those
two files – nothing about the directories they live in.
--no-index – compare two arbitrary paths that are not in a Git repo.-f <pathspec> – restrict the diff to the files that match the given
pathspec(s).So, for two files in the same directory:
git diff --no-index -f path/to/file1 path/to/file2
If you want to compare two directories (or all files in a repo) you can simply give the directories or use a wildcard:
git diff --no-index -f dir1 dir2 # compare two directories
git diff --no-index -f . . # compare all files in the current dir
git diff --no-index -f $(git ls-files) $(git ls-files) # compare all tracked files
The -f option is the key to limiting the diff to just the files you care
about.