【问题标题】:how can I see the differences in a designated file between a local branch and a remote branch?如何查看本地分支和远程分支之间指定文件的差异?
【发布时间】:2012-05-16 02:08:42
【问题描述】:

如何查看指定文件中本地分支和远程分支的差异?

我知道这个命令:

git diff <local branch> <remote-tracking branch>

但它给出了两个分支之间所有文件的差异,而我只关心一个指定文件的更改。

【问题讨论】:

    标签: git version-control git-diff


    【解决方案1】:

    看看git diff --help,它告诉你:

    git diff [options] <commit> <commit> [--] [<path>...]
    

    所以,你快到了。而不是:

    git diff <local branch> <remote-tracking branch>
    

    你可以使用:

    git diff <local branch> <remote-tracking branch> path/to/file
    

    【讨论】:

      【解决方案2】:

      虽然其他答案都可以,但您希望养成使用“--”作为文件路径分隔符的习惯。如果没有分隔符,分支名称、文件名和其他内容之间可能会混淆。

      git diff <local> <remote> -- /path/to/file
      

      还请注意,对于您的文件路径,您可以改为使用目录,例如 /path/to/,并且只获取该目录中文件的差异。您也可以尝试使用 'git difftool ...' 来获得视觉差异。

      【讨论】:

        【解决方案3】:

        像这样:

        git diff <local branch> <remote-tracking branch> /path/to/file
        

        【讨论】:

          猜你喜欢
          • 2022-01-23
          • 2012-04-07
          • 2016-06-17
          • 2019-02-16
          • 2012-12-07
          • 1970-01-01
          • 1970-01-01
          • 2013-04-30
          • 2018-09-12
          相关资源
          最近更新 更多