Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run a command for each git submodule in powershell?

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?

like image 991
Justin808 Avatar asked Jun 26 '26 05:06

Justin808


1 Answers

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.

like image 97
Chronial Avatar answered Jun 28 '26 02:06

Chronial



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!