Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do a git diff between branches and exclude one file

Tags:

git

This should be simple for someone, i just can't seem to get the right syntax. The situation is I have checked out one of my colleagues branches and I want to see the difference between this branch and the dev branch however I don't want to see the changes in one particular file (because it's a huge file). Here is what I have tried:

git diff origin/dev ':(exclude)package-lock.json'

git diff ':(exclude)package-lock.json' origin/dev

git diff -- . ':(exclude)package-lock.json' origin/dev

I know I'm close...

Note... I have been told that this question is a possible duplicate of this one: Want to exclude file from "git diff" however this is not the case. The accepted answer of that question is this:

git diff -- . ':(exclude)db/irrelevant.php'

however when i run this command on my system:

git diff -- . ':(exclude)package-lock.json'

I get nothing. The reason I get nothing is likely due to the fact that in this command It is never specified that I want a diff between my current branch and origin/dev. What i want is similar to the above answer but also indicating the difference between the current branch and a remote branch.

like image 775
Dallas Caley Avatar asked Sep 10 '25 20:09

Dallas Caley


1 Answers

The following works for me:

git diff branchname -- ':(exclude)filename'

like image 90
Raphayol Avatar answered Sep 13 '25 11:09

Raphayol