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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10757091/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 06:58:36  来源:igfitidea点击:

git: list of all changed files including those in submodules

gitgit-submodulesgit-diff

提问by 4eyes

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-only --diff-filter=ACMR ${revision} HEAD

It returns a list of files, including the submodule-path, but not the files within.

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

Example: I've updated a submodule. I commited the super-project. Now I want to get a list of all files which have been modified.

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

Do you know a way to get this done?

你知道有什么方法可以完成这项工作吗?

回答by VonC

Update 2017: as I mentioned in "see diff of commit on submodule in gitlab",

2017 年更新:正如我在“查看 gitlab 子模块上提交的差异”中提到的,



Original 2012 answer (pre 2017 Git 2.14)

2012 年原始答案(2017 年 Git 2.14 之前)

Maybe a simple line would be enough:

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

git submodule foreach --recursive git diff --name-status

That would actually list files in submodules withinsubmodules.
(The --recursiveoption comes from git1.7.3+)

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

回答by Jamey Sharp

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

您可以使用以下命令找出子模块在给定父模块提交时所处的版本git ls-tree

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

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 "" ]];
        then git diff --name-only --ignore-submodules=all --diff-filter=ACMR "" ""
        else git diff --name-only --ignore-submodules=all --diff-filter=ACMR "" "" | awk -v r= '{ print "" r "/" 
#!/bin/sh
echo "Listing changes for super module"
git diff  --name-only
subs=(`git submodule | awk '{print }'`)
for sub in ${subs[*]}; do
   lastrevision=`git diff   $sub | fgrep "Subproject" | head -n1 | awk '{print }'`
   cd $sub
   echo "Listing changes for $sub"
   git diff $lastrevision --name-only
   cd ..
done
}' fi for submodule in `git submodule | awk '{print }'` do old=$(git ls-tree $submodule | awk '{print }') new=$(git ls-tree $submodule | awk '{print }') (cd $submodule; compare $old $new $submodule) done } compare "" ""

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

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

回答by BlacKow

So, the very straightforward script that lists all changes compared to a revision

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

@echo off
if NOT %1.==. goto has_rev1

@echo git diff --name-only including submodules
@echo usage:
@echo ^ ^ %~n0 ^<revision1^> [^<revision2^>^|HEAD]
@exit /b 1

:has_rev1
setlocal
set rev1=%1
if %2.==. (set rev2=HEAD) else (set rev2=%2)

call :show_diff %rev1% %rev2%
exit /b
::eof

:show_diff
setlocal ENABLEDELAYEDEXPANSION
for /f "tokens=*" %%l in ('git --no-pager diff --name-only --ignore-submodules^=all --line-prefix^=%3 %1 %2') do set fwds=%%l & set bcks=!fwds:/=\! & echo !bcks! 
endlocal
::git submodule is too slow for this
::for /f "tokens=2" %%d in ('git submodule') do call :subm %1 %2 %%d %3
if exist .gitmodules for /f "tokens=1,3*" %%p in (.gitmodules) do if %%p.==path. call :subm %1 %2 %%q %3
exit /b
::show_diff

:subm
setlocal
for /f "tokens=3" %%r in ('git ls-tree %1 %3') do set rev1=%%r
for /f "tokens=3" %%r in ('git ls-tree %2 %3') do set rev2=%%r

set fwdslash=%3
set bckslash=%fwdslash:/=\%

pushd %bckslash%
call :show_diff %rev1% %rev2% %4%bckslash%\
popd

endlocal
exit /b
::subm

it takes one argument - revision you want to compare with. Make sure that there is fgrep "Subproject", not fgrep "Submodule".

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

回答by Pavel Studeny

A Windows variant of https://stackoverflow.com/a/13169898/5438298by Jamey Sharpwould be

Jamey Sharphttps://stackoverflow.com/a/13169898/5438298的Windows 变体将是

git diff --submodule=diff

(note that it might need a few more double quotes for spaces in the submodule names to work).

(请注意,子模块名称中的空格可能需要更多双引号才能工作)。

回答by Naman

July 8,2017

2017 年 7 月 8 日

Now to get a diff including that of a submodule, you can use the command -

现在要获得包括 a 的差异submodule,您可以使用命令 -

##代码##

Note - This has been introduced with Git 2.14.0

注意 - 这已在Git 2.14.0 中引入

"git diff --submodule=diff" now recurses into nested submodules.

“git diff --submodule=diff”现在递归到嵌套的子模块中。