3

I know there is some questions already around there as this one. In my case:

Let's say I have a repo R1 with a submodule SR2.

  1. I do a submodule commit in SR2.
  2. I commit the submodule update in R1
  3. I push the submodule update in R1
  4. I forgot to push in SR2

Then anyone who will clone repository R1 will get a reference is not a tree error, because obviously the submodule commit revision is only available locally currently.

If I then type git status in R1 repository, nothing warns me about the fact that my submodule is ahead of the remote repository.

If there any way to retrieve status recursively?

Community
  • 1
  • 1
bagage
  • 1,094
  • 1
  • 21
  • 44

1 Answers1

2

You can try a git submodule foreach command:

git submodule foreach --recursive 'git status  && echo'

You have other commands to show you the status of submodules in this answer, for changes in progress.


The OP Cqnqrd mentions in the comments:

To have better readability, I tweaked it a bit to the following alias:

Multiple-lines:

gss_command='git -c color.status=always status -s | \
             sed "s/^\(.*\)/\t\1/g" && git branch -v | \
             grep -E "ahead|behind" | \
             sed -r "s/[ *]\s(\S*).*(\[(ahead|behind).+?\]).*/\t\1 \2/g"' 

alias gs="git rev-parse --show-toplevel && \
          $gss_command && \
          git submodule foreach --recursive '$gss_command'"

one-liners:

gss_command='git -c color.status=always status -s | sed "s/^\(.*\)/\t\1/g" && git branch -v | grep -E "ahead|behind" | sed -r "s/[ *]\s(\S*).*(\[(ahead|behind).+?\]).*/\t\1 \2/g"' 

alias gs="git rev-parse --show-toplevel && $gss_command && git submodule foreach --recursive '$gss_command'"
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • To have better readibility, I tweaked it a bit to the following alias: `gss_command='git -c color.status=always status -s | sed "s/^\(.*\)/\t\1/g" && git branch -v | grep -E "ahead|behind" | sed -r "s/[ *]\s(\S*).*(\[(ahead|behind).+?\]).*/\t\1 \2/g"' alias gs="git rev-parse --show-toplevel && $gss_command && git submodule foreach --recursive '$gss_command'"` – bagage Jul 04 '14 at 06:19
  • @Cqnqrd great! I have included your comment in the answer for more visibility. – VonC Jul 04 '14 at 06:31
  • 1
    @Cqnqrd note: `git status --porcelain` is the one supposed to be parsed (see the end of http://stackoverflow.com/a/6978402/6309) – VonC Jul 04 '14 at 06:32
  • agree, but this (by design) lose coloration! It may depends on the usage you will make of it obviously. – bagage Jul 04 '14 at 07:17