Search code examples
gitgit-diffgit-diff-tree

How can I diff a tree and a remote branch in git?


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.


Solution

  • 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