Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 849
Ruobin Wang Avatar asked Feb 21 '23 11:02

Ruobin Wang


2 Answers

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
like image 50
larsks Avatar answered Apr 29 '23 03:04

larsks


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.

like image 21
GoZoner Avatar answered Apr 29 '23 02:04

GoZoner