如何在 git 中区分树和远程分支?

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

我需要在 git 中区分两个对象。一个是我工作目录下的树(目录),一个是远程分支。如果我找到树的 SHA 并将其用于 git diff 命令的参数以及远程分支,我就可以这样做。但是,我正在尝试找到一种不必先挖掘 SHA 的方法。

因此,例如,如果:

My_Working_Dir
  file1
  file2
  Dir1
    file3
    file4

remote_branch/master
  file3
  file4

那么我喜欢能够发出这样的东西:

git diff Dir1  remote_branch/master

如果我用它的 SHA 替换 Dir1,这会起作用,但如果我只是尝试使用目录名,则不会。我也尝试过使用 diff-tree。但这也无济于事。请注意 remote_branch/master 没有 Dir1 目录。

感谢任何帮助。

提前致谢。

您可以简单地在 -- 之后使用路径参数。

git diff remote_branch/master -- Dir1

您可以将 <branch>:<file_path> 符号与 git diff

一起使用

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

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