Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to git status (or show) only submodule changes?

Tags:

git

git status --ignore-submodules=all

I am looking for inverse of this, is there a way to print only the submodule changes? like git status --show-only-submodules

EDIT: My script fetch and merge submodule change, then it fetch and merge super project change. now, I need to check if the newly pulled-in super project change includes the SHA update of submodule change, for that I am thinking to do git show HEAD^ HEAD in super project, which prints below:

--- a/xyz
+++ b/xyz
@@ -1 +1 @@

-Subproject commit f991877822a8fd50b90f53894f2592a852039547
+Subproject commit f57c051f91b0948a5b8947430b516e650b50348e

from here, I will take the +Subproject commit and go into xyz directory, do a git log -1 --no-merges and compare the SHAs, if it matches, then I will assume the super change includes the submodule change that has been pulled in.

For this reason, I like to list only the submodule changes when I do git status --some-option being in the super project. please let me know if there is a better way to do the same.

like image 278
rodee Avatar asked Jun 15 '18 13:06

rodee


2 Answers

This should be the proper solution for you:

git submodule foreach git status

This will traverse all submodules and execute the given command. From here:

foreach [--recursive] <command>

Evaluates an arbitrary shell command in each checked out submodule. The command has access to the variables $name, $path, $sha1 and $toplevel: $name is the name of the relevant submodule section in .gitmodules, $path is the name of the submodule directory relative to the superproject, $sha1 is the commit as recorded in the superproject, and $toplevel is the absolute path to the top-level of the superproject. Any submodules defined in the superproject but not checked out are ignored by this command. Unless given --quiet, foreach prints the name of each submodule before evaluating the command. If --recursive is given, submodules are traversed recursively (i.e. the given shell command is evaluated in nested submodules as well). A non-zero return from the command in any submodule causes the processing to terminate. This can be overridden by adding || : to the end of the command.

As an example, the command below will show the path and currently checked out commit for each submodule:

git submodule foreach 'echo $path $(git rev-parse HEAD)'

like image 68
andreee Avatar answered Nov 06 '22 00:11

andreee


git submodule status

Show the status of the submodules. This will print the SHA-1 of the currently checked out commit for each submodule, along with the submodule path and the output of git describe for the SHA-1. Each SHA-1 will possibly be prefixed with - if the submodule is not initialized, + if the currently checked out submodule commit does not match the SHA-1 found in the index of the containing repository and U if the submodule has merge conflicts.

If --recursive is specified, this command will recurse into nested submodules, and show their status as well.

If you are only interested in changes of the currently initialized submodules with respect to the commit recorded in the index or the HEAD, git-status and git-diff will provide that information too (and can also report changes to a submodule’s work tree).

like image 35
Fabian S. Avatar answered Nov 06 '22 01:11

Fabian S.