how can I see the differences in a designated file between a local branch and a remote branch?

瘦欲@ 提交于 2019-12-06 05:03:44

问题


How can I see the differences in a designated file between a local branch and a remote branch?

I know this command:

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

But it gives the differences in all files between two branches while I only care about changes of one single designated file.


回答1:


Take a look at git diff --help, which shows you:

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

So, you're almost there. Instead of:

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

You can use:

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



回答2:


While the other answers will work, you want to get in the habit of using '--' as the file path separator. Without the separator there can be confusion between branch names, file names and perhaps other stuff.

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

also note that for your file path you can instead use a directory, such as /path/to/, and get only the difference for files in that directory. You might also try 'git difftool ...' for a visual diff.




回答3:


Like this:

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


来源:https://stackoverflow.com/questions/10611112/how-can-i-see-the-differences-in-a-designated-file-between-a-local-branch-and-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!