user776635
user776635

Reputation: 871

Can I git diff a subset of files between two branches

git diff branch..branch1 will generate all the difference between two branches.

is there a way to diff a given list of files?

'git diff branch..branch1 filename' can do it for just one file, what if I want to supply a list of files?

Upvotes: 0

Views: 933

Answers (3)

Tenbrink
Tenbrink

Reputation: 506

You can use glob patterns. For instance, if you have the following folder structure

  -project
    -client
      -...more folders
    -server
      -...more folders

from the project folder you could run the following commmand:

git diff client/**

which would give you a diff of everything in the client folder and subfolders, but ignore the server folders.

Upvotes: 0

Andreas Wederbrand
Andreas Wederbrand

Reputation: 40061

You can add -- <path> <path> and so on to git diff

Upvotes: 0

Ross
Ross

Reputation: 2179

You can do:

git diff branch..branch1 -- file1 file2

So if you have a filelist, you can use a shell expansion (in bash, for example) to enumerate the contents of your filelist.

> cat filelist
file1
file2
> echo $(cat filelist)
file1 file2
> git diff branch..branch1 -- $(cat filelist)

where the final command should be what you're looking for.

Upvotes: 1

Related Questions