Skip to main content

A bash script that can automate git commit message contents [Resolved]

Normally when I commit a change to a submodule in Git (and if that's the only change), I will provide the result of git diff to the body of the commit message (with diff.submodule set to log in my git config). So the message would look something like:

Updated Core Submodule

Submodule Core eaedd3f..0721763:
  < Fixed ZA-123: Crash in rendering module
  < Merge 'develop' into 'master'

I've been trying to write a script that will automate this, to which I can tie to an alias in my git config. To generate the text above, ideally I'd like to run a command such as:

$ git submodule-commit Core

This would perform the following (roughly):

  1. Stage any change to specified submodule (Core in this case)
  2. Diff the change to the submodule and store that output text for the message generated later
  3. Run git commit and provide the subject line (Updated $1 Submodule, or something of that sort, where $1 is Core in this example).
  4. Add the stored diff result from earlier to the commit message as well

I've not had any luck writing a simple script for this. I'm not very experienced with bash / shell scripts. Could anyone help provide an implementation that accomplishes this?


Question Credit: void.pointer
Question Reference
Asked March 23, 2019
Tags: scripting
Posted Under: Unix Linux
13 views
1 Answers

Your Answer