From the git-diff manpage:
git diff [--options] <commit> <commit> [--] [<path>...]
For instance, to see the difference for a file "main.c" between now and two commits back, here are three equivalent commands:
$ git diff HEAD^^ HEAD main.c
$ git diff HEAD^^..HEAD -- main.c
$ git diff HEAD~2 HEAD -- main.c
Answer from mipadi on Stack OverflowFrom the git-diff manpage:
git diff [--options] <commit> <commit> [--] [<path>...]
For instance, to see the difference for a file "main.c" between now and two commits back, here are three equivalent commands:
$ git diff HEAD^^ HEAD main.c
$ git diff HEAD^^..HEAD -- main.c
$ git diff HEAD~2 HEAD -- main.c
You can also compare two different files in two different revisions, like this:
git diff <revision_1>:<file_1> <revision_2>:<file_2>
How do I view file differences (not commits) between two branches in git?
do a git diff which simply compares the files of one commit with those of another
How do you create a diff file with all of the uncommitted changes?
Basic question - Does 'git diff' only show the difference between the two existing files
Videos
How do I view file differences (not commits) between two branches in git? Latest commit of course.
If I compare the branches I get different results depending on which order I choose them. Files that are different only show up on direction or the other. I want to view the raw file differences so I don't miss anything.
Edit: my colleague took care of it. I'm not sure what I was doing wrong.
I thought I was beginning to understand git diff.
But today I did a git diff between a commit at the tip of one branch ("A") with a commit at the tip of another ("B"), where tip of B is the newer commit. Thus I'm doing this:
> git diff [sha of tip of A] [sha of tip of B] > output_diff.txt
I'm quite baffled by the results, and in particular by the fact that lines which are present in neither commit's version of a given file (call it xxx.py) are included in the diff, with "++" at the start of the line.
These are all lines which **were** in branch A in the version of that file at one point ... but were then DELETED before the branch A tip commit was made. I'm baffled as to why these are there. They are of no interest to me, and make the diff file all the more difficult to understand.
Is there any way to just exclude these lines when doing a git diff?