2

I have two git branch.
I want to compare the same file in two git branch.
But I don't want to switch branch.
How to do it?

Magic
  • 1,182
  • 2
  • 18
  • 28

3 Answers3

4

You can use the following command to compare a single file between branches:

git diff branch1 branch2 -- myfile.test
jvperrin
  • 3,368
  • 1
  • 23
  • 33
1

git diff is a powerful tool that lets you compare across commits, branches, and even just what you've got changed since your last commit.

In order to compare across branches, use: git diff first_branch second_branch -- fileInQuestion.js

SomeKittens
  • 38,868
  • 19
  • 114
  • 143
0

From the git man page:

git diff [--options] <commit> <commit> [--] [<path>…]
    This is to view the changes between two arbitrary <commit>.

Use the two different sha codes that you want to difference:

git diff <sha1> <sha2> -- ./path/to/file/to/compare

The sha commit code can be on the same branch, or not.

PaulProgrammer
  • 16,175
  • 4
  • 39
  • 56