Search code examples
gitgit-diffgit-diff-tree

Can you do a 'git diff' on 2 branches but limit it to only one directory sub-tree?


I am working on a large web project that has oodles of code for doing RESTful APIs, authentication, etc., etc. A large team does all that. I work solely on the scinetific computational kernel of the project, which is about 20 files in one directory.

Is there a way to do a 'git diff' between two branches which is restricted only to those files in the single directory?

If I do a 'git diff master my_branch' I see the deltas in hundreds of files that I have nothing to do with. I can, of course, do it file by file in the directory I care about by doing 'git diff master my_branch -- file1', 'git diff master my_branch -- file 2', etc., but that is very tedious.

What I would like to do is essentially 'git diff master my_branch -- /root/foo/scientific_modules/*.py' or something like that.


Solution

  • Assuming that the name of your directory is "root" and you are executing command inside of it, just exclude "root" from the path option (as it is in example from your question):

    git diff master my_branch -- foo/scientific_modules/*.py