问题
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