Git: How to diff two different files in different branches?

Sidenote: no need for full paths, you can start with ./ for relative paths. It can be handy sometimes.

git diff branch1:./relative/path/to/foo.txt branch2:./relative/path/to/foo-another.txt

Off-topic answer -- diffing the same file in different branches

Just to add it for I find it a very straightforward syntax :

git diff <branch1> <branch2> <filepath>

Also works with relative refs like for example :

# compare the previous committed state from HEAD with the state branch1 was 3 commits ago
git diff HEAD^ <branch1>~3 <filepath>

git diff branch1:full/path/to/foo.txt branch2:full/path/to/foo-another.txt

You can also use relative paths:

git diff branch1:./relative/path/to/foo.txt branch2:./relative/path/to/foo-another.txt

Tags:

Git

Git Diff