Search code examples
gitmodulegit-diff

How to show git diff --name-only between 2 branches for a specific module (or multiple modules) within a repo


I am trying to work out a way to get git to show the list of "name only" changes between 2 commit points (be them tags or branches) for a specific submodule.

I can do this easily using git diff for a single repo by doing the following:

git diff --name-only commitPointA..commitPointB

(Here is another answer that talks about this for reference purposes)

But this lists all the file changes for the repository that I am running the command within.

How can I refine the change list to only display the changes to a certain module, or a collection of modules within the same repo?


Solution

  • @torek pointed me in the right direction suggesting I look at the <path> argument. Here is what I did to get a refined list by module.

    Changes within a single module...

    git diff --name-only commitPointA..commitPointB ./moduleA
    

    Changes within multiple modules...

    git diff --name-only commitPointA..commitPointB ./moduleA ./moduleB
    

    Its probably worth stating here that the module name simply represents the name of the root folder for that module within the repo.

    That's it, simple in the end.


    An alternative to specifying by path is to just pipe the output through grep and specify something you know you're really interested in like a module name (I know it sounds obvious).

    Here is a simple example:

    git diff --name-only commitPointA..commitPointB | grep 'module-name'
    

    You could expand this to search for multiple values as well, just checkout the grep man page for more information.