git: list of all changed files including those in submodules

前端 未结 6 1712
死守一世寂寞
死守一世寂寞 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:26

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

    @echo off
    if NOT %1.==. goto has_rev1
    
    @echo git diff --name-only including submodules
    @echo usage:
    @echo ^ ^ %~n0 ^ [^^|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
    

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

提交回复
热议问题