git diff two files on same branch, same commit

If you want to use git diff on two arbitrary files you can use git diff --no-index <file_a> <file_b>. The two files do not need to be tracked in git for this to work.


You don't need git for that, just use diff fileA.php fileB.php (or vimdiff if you want side by side comparison)


If the files you want to compare are in your working copy, you can use simply diff as pointed by the others, however if the files are in some revision you can specify a revision for each file

git diff <revision_1>:<file_1> <revision_2>:<file_2>

as noted here: https://stackoverflow.com/a/3343506/1815446

In your case (specifying the same revision for both files):

git diff <revisionX>:fileA.php <revisionX>:fileB.php

To make regular gnu diff look more like git diff, I would recommend these parameters:

diff -burN file_or_dir1 file_or_dir2

(where -b ignore spaces, -u unified diff, -r recursive, -N treat missing files as /dev/null).

It works great, but still does not have colors and git-style auto-paging is virtually absent. If you want to fix both (I do), install colordiff and use it like this:

colordiff -burN file_or_dir1 file_or_dir2 | less -R

This gives output and interface that is very close to actual git diff.