Better Git Diff Outputs with Git Submodules

Featured image for sharing metadata for article

I've recently been playing around with Git Submodules a little bit more, and have been frustrated by the output of git diffs:

diff --git a/vendor/git/startbootstrap-clean-blog b/vendor/git/startbootstrap-clean-blog
index eda0a67..5daffc9 160000
--- a/vendor/git/startbootstrap-clean-blog
+++ b/vendor/git/startbootstrap-clean-blog
@@ -1 +1 @@
-Subproject commit eda0a676f655da9e909464eec6a028757b880bf0
+Subproject commit 5daffc976c4a8769129f98733c961a0df90d0246

When trying to write commit messages, via Viewing your diff while writing your commits with git commit --verbose, I've found that there's nothing really useful in the diff that I can describe as I'm writing the commit. To gain some understanding of what's happened in the submodule, I run:

$ git log --oneline eda0a676f655da9e909464eec6a028757b880bf0...5daffc976c4a8769129f98733c961a0df90d0246
5daffc9 Centre-align site subtitle
e51780f Make site subtitle bold

This would then be added to a commit message such as:

Theme: Subtitle changes

5daffc9 Centre-align site subtitle
e51780f Make site subtitle bold

However, after getting annoyed by this I've now discovered some other options, thanks to Stack Overflow, which can make it much easier to view changes with.

diff Format

Perhaps the most useful of the options is an actual diff of changes within the submodule:

Submodule vendor/git/startbootstrap-clean-blog eda0a67..5daffc9:
diff --git a/vendor/git/startbootstrap-clean-blog/assets/vendor/startbootstrap-clean-blog/scss/_masthead.scss b/vendor/git/startbootstrap-clean-blog/assets/vendor/startbootstrap-clean-blog/scss/_masthead.scss
index f564652..fceee82 100644
--- a/vendor/git/startbootstrap-clean-blog/assets/vendor/startbootstrap-clean-blog/scss/_masthead.scss
+++ b/vendor/git/startbootstrap-clean-blog/assets/vendor/startbootstrap-clean-blog/scss/_masthead.scss
@@ -37,8 +37,9 @@ header.masthead {
       margin-top: 0;
     }
     .subheading {
+      text-align: center;
       font-size: 24px;
-      font-weight: 300;
+      font-weight: bold;
       line-height: 1.1;
       display: block;
       margin: 10px 0 0;

You can set this as your default by running:

# either
$ git config --global diff.submodule diff
# or
$ git config --global -e

And adding:

[diff]
  submodule=diff

short Format

short simply shows the commit at the beginning and the end of a stage, such as:

diff --git a/vendor/git/startbootstrap-clean-blog b/vendor/git/startbootstrap-clean-blog
index eda0a67..5daffc9 160000
--- a/vendor/git/startbootstrap-clean-blog
+++ b/vendor/git/startbootstrap-clean-blog
@@ -1 +1 @@
-Subproject commit eda0a676f655da9e909464eec6a028757b880bf0
+Subproject commit 5daffc976c4a8769129f98733c961a0df90d0246

This is Git's default, but to always have this setting, you can run:

# either
$ git config --global diff.submodule short
# or
$ git config --global -e

And adding:

[diff]
  submodule=short

log Format

Alternatively, you can get a log format, which is nice for putting in a CHANGELOG/commit message:

Submodule vendor/git/startbootstrap-clean-blog eda0a67..5daffc9:
  > Centre-align site subtitle
  > Make site subtitle bold

You can set this as your default by running:

# either
$ git config --global diff.submodule log
# or
$ git config --global -e

And adding:

[diff]
  submodule=log

Written by Jamie Tanna's profile image Jamie Tanna on , and last updated on .

Content for this article is shared under the terms of the Creative Commons Attribution Non Commercial Share Alike 4.0 International, and code is shared under the Apache License 2.0.

#blogumentation #git #command-line.

Also on: Lobste.rs logo

This post was filed under articles.

Interactions with this post

Interactions with this post

Below you can find the interactions that this page has had using WebMention.

Have you written a response to this post? Let me know the URL:

Do you not have a website set up with WebMention capabilities? You can use Comment Parade.