git: list of all changed files including those in submodules

前端 未结 6 1721
死守一世寂寞
死守一世寂寞 2020-12-08 02:53

I would like to get a list of all files, which have changed betweet two commits including those in submodules.

I know I can do this:

git diff --name-         


        
6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-08 03:14

    You can find out what version a submodule was at, as of a given parent module commit, using git ls-tree:

    subcommit=$(git ls-tree $parentcommit $submodulepath | awk '{print $3}')
    

    So here's a script that should get you much of the way there, up to output formatting and such:

    #!/bin/sh
    
    function compare {
        if [[ -z "$3" ]];
            then git diff --name-only --ignore-submodules=all --diff-filter=ACMR "$1" "$2"
            else git diff --name-only --ignore-submodules=all --diff-filter=ACMR "$1" "$2" | awk -v r=$3 '{ print "" r "/" $0}'
        fi
    
        for submodule in `git submodule | awk '{print $2}'`
        do
            old=$(git ls-tree $1 $submodule | awk '{print $3}')
            new=$(git ls-tree $2 $submodule | awk '{print $3}')
            (cd $submodule; compare $old $new $submodule)
        done
    }
    
    compare "$1" "$2"
    

    This will output all files like this (although Base is a submodule): HtmlTemplates/Css/Screen.css Base/Php/Classes/Helper.php

提交回复
热议问题