2

I tried running this command:

git submodule --quiet foreach "echo $name"

to get all submodules' names, but it returns nothing. In Linux, it works as expected.

I am using Windows 7, git version 2.1.1 under Cygwin.

Amumu
  • 17,924
  • 31
  • 84
  • 131

2 Answers2

3

Cygwin means unix-like environment.

As you can see in other git submodule foreach examples (like "Bash: Git submodule foreach?"), all those commands are using single quotes around the foreach directive (as commented by Stefan Näwe)

This thread do mention in the example:

git submodules foreach 'git config -f $toplevel/.git/config submodule.$name.ignore all' 

Note the single quote (double quotes did not work from msysgit bash shell)


But as I mentioned in "git submodule foreach - Robust way to recursively commit a child module first?", with git 1.9.0+ (and commit 1c4fb13), you could also try without quotes:

git submodule --quiet foreach echo $name

As commented by Stefan Näwe, you would need to do a git submodule update --init --recursive first, before any foreach directive.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Well it didn't work at all. Probably I should re-install Git? – Amumu Nov 15 '14 at 14:16
  • @Amumu did you try outside Cygwin, in a basic cmd, with Git for Windows 1.9.4? (https://github.com/msysgit/msysgit/releases/) – VonC Nov 15 '14 at 14:18
  • @Amumu are you sure the submodules are really there ? Did you clone with `--recursive` or did you do `git submodule update -i` after `git clone` ? – Stefan Näwe Nov 15 '14 at 14:35
  • @StefanNäwe It's true that I forgot to clone the submodules first. Silly me. It works now for single quote. – Amumu Nov 15 '14 at 17:34
0

There is no way that this worked as expected on Linux. The reason is that double quote is shell's weaker quote... which means that it allowed variable expansion. That means the shell you are typing it into will do the expansion based on your current shell, and then pass it to git. So git will see "echo ", and nothing interesting will happen. You need to use single quotes which prevents variable expansion, so that the string reaches git unmolested.

xpusostomos
  • 1,309
  • 11
  • 15
  • I believe that is what I mention in [my answer](https://stackoverflow.com/a/26944020/6309) indeed. – VonC Jan 21 '22 at 07:43