1

I have 2 different files foo and bar.

Each one is on 2 different commits, on the same branch, respectively with SHA1 SHA1-foo and SHA1-bar. I want to see a diff between those 2 files.

I could checkout one of the files and copy it but maybe there's a better way.

Trevor Reid
  • 3,310
  • 4
  • 27
  • 46
bemug
  • 1,694
  • 2
  • 12
  • 10
  • possible duplicate of [git diff commits difference](http://stackoverflow.com/questions/1191282/git-diff-commits-difference) – nwinkler Jul 17 '15 at 09:33
  • possible duplicate of [Git: How to diff two different files in different branches?](http://stackoverflow.com/questions/8131135/git-how-to-diff-two-different-files-in-different-branches) – scrowler Jul 17 '15 at 09:34
  • It's not the same as the commits difference, because I want 2 different files, not the same files. – bemug Jul 17 '15 at 09:35
  • The question with branches is similar, but here I want 2 different commits on the same branch instead of 2 different branches, see my answer. – bemug Jul 17 '15 at 09:37
  • It's the same syntax, obviously. What's the point in having a QA for any slight variation of the question ? – Denys Séguret Jul 17 '15 at 09:45
  • I didn't knew it was the same syntax. It wasn't obvious for me. Feel free to remove if you think it's needed. – bemug Jul 17 '15 at 09:47

2 Answers2

5

I found that it works the same way as branches, see this SO thread.

git diff SHA1-foo:/path/to/foo SHA1-bar:/path/to/bar
Community
  • 1
  • 1
bemug
  • 1,694
  • 2
  • 12
  • 10
  • By the way you need to specify both branches otherwise it will not work. Git will not use your current branch as default. – bemug Jul 23 '15 at 08:01
3

You can do:

git diff branch1:file branch2:file
nwinkler
  • 52,665
  • 21
  • 154
  • 168
Astrogat
  • 1,617
  • 12
  • 24
  • Yes that's the idea except that it's for different commits instead of different branches, but it seems to work the same way. See my answer. – bemug Jul 17 '15 at 09:40
  • 1
    Oh, I misread the question. Yeah, in that case you are correct. – Astrogat Jul 17 '15 at 09:41