git:所有已更改文件的列表,包括子模块中的文件

4ey*_*yes 33 git git-diff git-submodules

我想获得所有文件的列表,这些文件已在两个提交之间发生了变化,包括子模块中的提交.

我知道我可以这样做:

git diff --name-only --diff-filter=ACMR ${revision} HEAD
Run Code Online (Sandbox Code Playgroud)

它返回一个文件列表,包括子模块路径,但不包括其中的文件.

示例:我更新了一个子模块.我提交了超级项目.现在我想获得已修改的所有文件的列表.

你知道如何完成这项工作吗?

Von*_*onC 29

更新2017:正如我在" 参见gitlab中子模块提交的差异 "中所提到的,


2012年原创答案(2017年前Git 2.14)

也许一条简单的线就足够了:

git submodule foreach --recursive git diff --name-status
Run Code Online (Sandbox Code Playgroud)

子模块中,将实际列出的文件中的子模块.
(该--recursive选项来自git1.7.3 +)


Jam*_*arp 5

您可以使用来确定子模块在给定父模块提交时所处的版本git ls-tree

subcommit=$(git ls-tree $parentcommit $submodulepath | awk '{print $3}')
Run Code Online (Sandbox Code Playgroud)

因此,这里有个脚本,应该可以帮助您了解大部分内容,包括输出格式等:

#!/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"
Run Code Online (Sandbox Code Playgroud)

这将输出所有这样的文件(尽管Base是一个子模块):HtmlTemplates / Css / Screen.css Base / Php / Classes / Helper.php


Bla*_*Kow 3

因此,非常简单的脚本列出了与修订版相比的所有更改

#!/bin/sh
echo "Listing changes for super module"
git diff $1 --name-only
subs=(`git submodule | awk '{print $2}'`)
for sub in ${subs[*]}; do
   lastrevision=`git diff  $1 $sub | fgrep "Subproject" | head -n1 | awk '{print $3}'`
   cd $sub
   echo "Listing changes for $sub"
   git diff $lastrevision --name-only
   cd ..
done
Run Code Online (Sandbox Code Playgroud)

它需要一个参数 - 您想要与之比较的修订版。确保有fgrep "Subproject",没有fgrep "Submodule"