Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git: list of all changed files including those in submodules

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?

like image 202
4eyes Avatar asked May 25 '12 15:05

4eyes


People also ask

Does git pull include submodules?

Pulling with submodules. Once you have set up the submodules you can update the repository with fetch/pull like you would normally do. To pull everything including the submodules, use the --recurse-submodules and the --remote parameter in the git pull command .

Does git pull also update submodules?

With Git 2.34, if the repository is cloned with the --recurse-submodules , a simple git pull will recurse into submodules.

Is using git submodules a good idea?

Git submodules may look powerful or cool upfront, but for all the reasons above it is a bad idea to share code using submodules, especially when the code changes frequently. It will be much worse when you have more and more developers working on the same repos.

Where can I find Gitmodules?

gitmodules file, located in the top-level directory of a Git working tree, is a text file with a syntax matching the requirements of git-config[1]. The file contains one subsection per submodule, and the subsection value is the name of the submodule.


2 Answers

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

  • Git 2.11 (Nov. 2016) introduces

    git diff --submodule=diff 
  • Git 2.14 (Q3 2017) will improve that by recursing into nested submodules.
    See commit 5a52214 (04 May 2017) by Stefan Beller (stefanbeller).
    (Merged by Junio C Hamano -- gitster -- in commit a531ecf, 29 May 2017)


Original 2012 answer (pre 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 within submodules.
(The --recursive option comes from git1.7.3+)

like image 82
VonC Avatar answered Oct 04 '22 00:10

VonC


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

like image 35
Jamey Sharp Avatar answered Oct 04 '22 00:10

Jamey Sharp