Search code examples
gitgit-submodules

Git Submodule foreach alias to commit work


I have an alias set up for to commit all modified files in a packages submodules with a commit message. This used to work but lately it has stopped working guessing due to a git update.

The alias looks like this

    SubmoduleCommit = "!f() { git submodule foreach  'git commit --all --message=$1 || :'; }; f"

But it is no longer working, any ideas what would have changed. The error is that message requires a value so will not preform the git action. If i copy the code into bash and replace the $1 with "Commit message" then it works fine.


Solution

  • The problem you have is that inside the double quotes variables are immediately expanded. In your case $1 is expanded to nothing because it was never assigned. Instead, withing single quotes, there is no expansion and the string is copied as you see it (except when you escape with \).

    git config alias.SubmoduleCommit '!f() { git submodule foreach  "git commit --all --message=$1 || :"; }; f'
    

    You can see how your aliases look like with

    git config --list | grep "^alias\."