Git diff for specific files in different folders

Viewed 146

I have the following folder structure:

| folder1 
│   ├── file1
│   ├── file2
│   ├── file3
│   ├── file4
│   ├── file5
│   ├── fileN



| folder2 
│   ├── file1
│   ├── file2
│   ├── file3
│   ├── file4
│   ├── file5
│   ├── fileN

I would like to check the differences between files 1, 2, 5 and 15. Is there a way to use git diff to check the differences between these files, without being:

git diff folder1/file1 folder2/file1 

git diff folder1/file2 folder2/file2

git diff folder1/file5 folder2/file5

Is it possible to write the file names into a document and ask git to check the differences?

Best Regards

3 Answers

You can ask git diff to compare two trees (a "tree" is a directory in git technical terms, and represents an object in git's storage), and specify the files to compare afterwards :

git diff HEAD:folder1/ HEAD:folder2/ -- file1 file2 file5

You may try difftool -d, which will invoke an external diff viewer, and will probably offer a better UI experience :

git difftool -d HEAD:folder1/ HEAD:folder2/
# or :
git difftool -d HEAD:folder1/ HEAD:folder2/ -- file1 file2 file5

This is to answer the very last line of your question:

Is it possible to write the file names into a document and ask git to check the differences?

Whenever you have information in a file that you want to use as command line argugments, you can read that file into the command line using backticks or the $(...) notation.

If I take @LeGEC's solution:

git diff HEAD:folder1/ HEAD:folder2/ -- file1 file2 file5

and I place the files names into a file I'll call filelist

$ cat filelist
file1
file2
file5

then I can read the list of files right into the command line like this:

git diff HEAD:folder1/ HEAD:folder2/ -- $(cat filelist)

This should work:

git diff HEAD:folder1/file1 HEAD:folder2/file1
Related