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

git diff, external diff tool, and submodules

From
GPGrégory Pakosz <gregory.pakosz@gmail.com>
Date
Feb 15, 2014, 12:19 UTC
Message-ID
<CAC_01E0Pu+_UeSniFVhaqfu90d=iaFDqLrKZ1zjM6GMA4BvcGQ@mail.gmail.com>
Hello,
When a submodule has new commits, I noticed the following:
$ git diff
diff --git a/submodule b/submodule
index 4c75be6..b272d40 160000
--- a/submodule
+++ b/submodule
@@ -1 +1 @@
-Subproject commit 4c75be6435cd515887d35c300ed8b487f8143d8e
+Subproject commit b272d4077fda29028c0bd02efba2837e12a8319c

As you can see, the diff shows the submodule has new commits.

However when using an external diff tool, it seems to me that git diff
fails to handle the submodule case:

$ GIT_EXTERNAL_DIFF=echo git diff
submodule /var/folders/1h/q9nt7m6d2fs61_v177kq1_h00000gn/T//cz1ati_submodule
4c75be6435cd515887d35c300ed8b487f8143d8e 160000 submodule
0000000000000000000000000000000000000000 160000

$LOCAL is set to a temp file that contains:
Subproject commit 4c75be6435cd515887d35c300ed8b487f8143d8e

And I expected $REMOTE to be set to another temp file that contains:
Subproject commit b272d4077fda29028c0bd02efba2837e12a8319c

Instead, $REMOTE is set to the actual submodule path and then visual
diff tools rightfully complains $REMOTE doesn't point to a valid file.

I think git diff should handle the submodule case and create 2
temporary files containing "Subproject commit sha1" for external diff
tools to compare.

What do you think?
Gregory

PS: git difftool has a special "directory mode" triggered with "-d"
that does what git diff does when GIT_EXTERNAL_DIFF is not set. It
creates temp files with "Subproject commit sha1" lines for diff tools
to compare.
Next: Thomas Rast
Message 1 of 6 in “git diff, external diff tool, and submodules”
  1. Grégory PakoszFeb 15, 2014
  2. diff: do not reuse_worktree_file for submodulesThomas Rast, Feb 16, 2014
  3. Junio C HamanoFeb 18, 2014
  4. Thomas RastFeb 22, 2014
  5. Thomas RastFeb 23, 2014
  6. Junio C HamanoFeb 24, 2014

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.