Reputation: 23211
sorry if this question exists, I surprisingly could not find it :/
How can I perform a git diff
between two files within the same branch & same commit?
i.e. git diff fileA.php fileB.php
(ideally with the easy to read color coding that git
offers....or similar to what the program BeyondCompare does!)
Upvotes: 128
Views: 56115
Reputation: 116407
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
.
Upvotes: 6
Reputation: 3306
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.
Upvotes: 301
Reputation: 1143
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
Upvotes: 18
Reputation: 8255
If you want to diff two local files in the same directory just use diff.
diff fileA.php fileB.php
Upvotes: 0
Reputation: 22545
You don't need git for that, just use diff fileA.php fileB.php
(or vimdiff if you want side by side comparison)
Upvotes: 94