3

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.

Dallas Caley
  • 5,367
  • 6
  • 40
  • 69
  • 1
    Possible duplicate of [Want to exclude file from "git diff"](https://stackoverflow.com/questions/10415100/want-to-exclude-file-from-git-diff) – Obsidian Age Feb 06 '18 at 20:05
  • It's not a duplicate, this is the post i went to to get what i tried already but it doesn't work in my particular case. – Dallas Caley Feb 06 '18 at 20:06
  • when i run the suggested answer: 'git diff -- . ':(exclude)package-lock.json' i get no results because i'm not specifying origin/dev anywhere, but I can't figure out how to also specify that – Dallas Caley Feb 06 '18 at 20:08

2 Answers2

7

The following works for me:

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

Raphayol
  • 1,266
  • 11
  • 14
2

You have to list paths last. You have to have an include path to have exclude paths. Some of your attempts do each of these, but none do all :)

git diff origin/dev -- . ':!/package-lock.json'
Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52