← Back to Upcase

Diff'ing a working tree file against another branch

(Jon Seidel) #1

Has anyone been able to run a diff (or mergetool) between a working tree file and the same file in a separate branch? I’ve reviewed the docs which seems to indicate I can do this:

git diff [options] <commit> <commit> [--] [<path>...]

A ‘commit’ in this case, seems to allow a branch name (at least that’s what I get from man gitrevisions but it’s a bit confusing. I’ve googled and found all kinds of suggestions, but none of them work for me:

git diff <branch> -- <file>
git diff <branch>:<file> <file>
git diff <branch>:<file> -- <file>

At this point, I’m just flailing around and hoping someone has the solution!

(Tim Habermaas) #2
git diff feature-1:Gemfile Gemfile

does work for me. Are there any errors you get?

(Jon Seidel) #3
fatal: ambiguous argument 'features/step_definitions/error_scenarios.rb': unknown revision or path not in the working tree.

In this case the file didn’t exist in both branches (that was a surprise), but I’ve had other situations where I get no response… let me find a better example.

OK; thank you very much - that is the correct syntax. If there are no changes, the command silently ends…