7

I have a meta project with a number of submodules in it. I would like to run the following lines inside a foreach loop of some kind.

cd $subDirectory
"\n\nModule $subDirextory" >> log
git log --pretty=format:"%h%x09%an%x09%ad%x09%s" origin/${Branch}..HEAD >> log
cd ..

The idea is to get a log from the last branch point up to HEAD for each submodule in the meta repo. How can I go about doing this?

Justin808
  • 20,859
  • 46
  • 160
  • 265

1 Answers1

7

The command you are looking for is probably:

git submodule foreach 'git log --pretty=format:"%h%x09%an%x09%ad%x09%s" @{u}..HEAD'

git submodule foreach will loop over all the submodules, cwd into them and run the given command. It will also output the name of each of the submodules before doing that.

@{u} refers to the remote tracking branch of the currently checked out branch.

The part I’m not sure about is quoting in PowerShell. The command given above will work in bash. You will have to make sure yourself that the part within ' is passed to git without modifications.

Chronial
  • 66,706
  • 14
  • 93
  • 99