【问题标题】:How can I diff a tree and a remote branch in git?如何在 git 中区分树和远程分支?
【发布时间】:2015-01-02 17:01:24
【问题描述】:

我需要区分 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,这会起作用,但如果我只是尝试使用目录名称,则不会。我也尝试过使用差异树。但这也无济于事。请注意,remote_branch/master 没有 Dir1 目录。

感谢任何帮助。

提前致谢。

【问题讨论】:

    标签: git git-diff git-diff-tree


    【解决方案1】:

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

    git diff remote_branch/master -- Dir1

    【讨论】:

    • 谢谢 Jiri,我试过了。但是,从输出来看,它的行为就像 Dir1 中的文件(对应于 remote_branch 中的文件)为空一样。有什么想法我可能做错了吗?
    • 我想我知道为什么这不起作用。该命令假定路径存在于 HEAD 和 remote_branch/master 中。虽然它确实存在于 HEAD 中,但就我而言,它不存在于 remote_branch/master 中。
    【解决方案2】:

    您可以将<branch>:<file_path> 符号与git diff 一起使用

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

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

    【讨论】:

    • 太棒了。由于我有很多文件,我注意到以下作品 git diff remote_branch HEAD:Dir1
    • 好的,很好。很高兴我能帮上忙。
    猜你喜欢
    • 1970-01-01
    • 2015-04-24
    • 2012-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-12
    • 2010-12-19
    相关资源
    最近更新 更多