0

I need to diff two objects in git. One is a tree (directory) in my working directory, and the other one is a remote branch. I can do so if I find the SHA of the tree and use that in the argument of my git diff command along with the remote branch. However, I am trying to find a way not to have to dig in the SHA first.

So, for example, if:

My_Working_Dir
  file1
  file2
  Dir1
    file3
    file4

remote_branch/master
  file3
  file4

Then I like to be able to issue something like this:

git diff Dir1  remote_branch/master

This works if I replace Dir1 with its SHA, but not if I just try to use the directory name. I have tried to use diff-tree as well. But that is not helping either. Please note that the remote_branch/master does not have the Dir1 directory.

Any help is appreciated.

Thanks in advance.

MrAliB
  • 799
  • 9
  • 17

2 Answers2

2

You can use <branch>:<file_path> notation with git diff

git diff remote_branch/master:file3 HEAD:Dir1/file3

git diff remote_branch/master:file4 HEAD:Dir1/file4

Dan Fischer
  • 3,769
  • 1
  • 14
  • 10
1

You can simply use the path argument after the --.

I.e.

git diff remote_branch/master -- Dir1

Jiri Kremser
  • 12,471
  • 7
  • 45
  • 72
  • Thanks Jiri, I tried this. However, from the output, it appears that it behaves as if the files in Dir1 (corresponding to the files in the remote_branch) are empty. Any ideas what I may be doing wrong? – MrAliB Jan 02 '15 at 17:39
  • I think I know why this is not working. The command assumes the path exist in both HEAD and remote_branch/master. While it is true that it exists in the HEAD, for my case, it does not exist in remote_branch/master. – MrAliB Jan 02 '15 at 17:49