git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git diff across submodules

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 18, 2012, 19:28 UTC
Message-ID
<7vobl3m8pb.fsf@alter.siamese.dyndns.org>
In-Reply-To
<5058C53B.5040401@web.de>
Jens Lehmann <Jens.Lehmann@web.de> writes:
Show 8 quoted lines
> Am 18.09.2012 05:12, schrieb Kenny Simpson:
>>   Is there any nice way to get a diff and/or diffstat of both a project and its submodules between two revisions of the main project?
>> 
>> Something like 'git diff --stat tag_a tag_b' but also including the diffstat on the submodule from the revision tied to in tag_a to the revision tied to tag_b.  A few shell backflips will do it, but this seems like I'm missing something.
>
> Unfortunately that isn't possible yet, "git diff" still has to learn the
> --recurse-submodules option. And as far as I know, nobody is currently
> working on that.
I do not think it is _that_ unfortunate, at least for two reasons.

When I made something a submodule, not a plain vanilla directory, I did want it to be treated differently from a collection of files in random states (which is what a directory is), but as a logical unit. If I bind another project 'frotz' at my path 'lib/frotz' and ask for diff of two versions of my superproject, e.g.

    $ git diff v1.0 v1.1

I am more interested in finding out that we used to use v2.5 of 'frotz' back when we were at v1.0 but in our v1.1 we downgraded it to v2.4, perhaps because we found a regression in the 'frotz' library, rather than the whole reverse differences between v2.4 and v2.5 of the frotz project. That difference, when I want to, I can get by going to that submodule and grab it myself with

    $ cd lib/frotz &7 git diff v2.4 v2.5

I also suspect that you do not have to change "git diff" at all to show the patch recursively by using the attribute mechanism (look in Documentation/gitattributes.text for a string GIT_EXTERNAL_DIFF). It might be just as simple as doing this:

	echo >.gitattributes "/lib/frotz diff=subrecurse" 
	git config diff.subrecurse.command $HOME/bin/diff-subrecurse
        cat >$HOME/bin/diff-subrecurse <<\-EOF
	#!/bin/sh
        path=$1 old_hex=$3 new_hex=$6
        unset GIT_DIR
        cd "$path" || exit 1
        git diff "$old_hex" "$new_hex"        
        EOF
        chmod +x $HOME/bin/diff-subrecurse

The corner cases like "new submodule", "removed submodule" are left as an exercise to the reader ;-)

Previous: Jens LehmannNext: Junio C Hamano
Message 3 of 6 in “git diff across submodules”
  1. Kenny SimpsonSep 18, 2012
  2. Jens LehmannSep 18, 2012
  3. Junio C HamanoSep 18, 2012
  4. Junio C HamanoSep 19, 2012
  5. Jens LehmannSep 20, 2012
  6. Junio C HamanoSep 20, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.