【发布时间】:2012-05-16 02:08:42
【问题描述】:
如何查看指定文件中本地分支和远程分支的差异?
我知道这个命令:
git diff <local branch> <remote-tracking branch>
但它给出了两个分支之间所有文件的差异,而我只关心一个指定文件的更改。
【问题讨论】:
标签: git version-control git-diff
如何查看指定文件中本地分支和远程分支的差异?
我知道这个命令:
git diff <local branch> <remote-tracking branch>
但它给出了两个分支之间所有文件的差异,而我只关心一个指定文件的更改。
【问题讨论】:
标签: git version-control git-diff
看看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
【讨论】:
虽然其他答案都可以,但您希望养成使用“--”作为文件路径分隔符的习惯。如果没有分隔符,分支名称、文件名和其他内容之间可能会混淆。
git diff <local> <remote> -- /path/to/file
还请注意,对于您的文件路径,您可以改为使用目录,例如 /path/to/,并且只获取该目录中文件的差异。您也可以尝试使用 'git difftool ...' 来获得视觉差异。
【讨论】:
像这样:
git diff <local branch> <remote-tracking branch> /path/to/file
【讨论】: