Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to provide a prepared git commit message?

By convention I create my story branches in git to include Jira issue ids in them, e.g. FOO-1001. I have a script to do that for me. Now, I have prepared another script that fetches the title of FOO-1001 from Jira API. I want to achieve that when I type:

$ git commit

My editor opens up prefilled with the following:

BUGFIX: FOO-1001 Some sample issue title downloaded using my script

What is the easiest way to achieve this using the scripts I described? My idea is to somehow format the commit message to a file so that git can find it and use as default. One way seems to be to use prepare-commit-msg hook, but I would prefer to achieve my goal using a standalone script, without any configuration in .git (so that my colleagues can easily reuse it).

like image 979
VoY Avatar asked Mar 21 '13 20:03

VoY


People also ask

What is the command to commit a message in git?

The content to be committed can be specified in several ways: by using git-add[1] to incrementally "add" changes to the index before using the commit command (Note: even modified files must be "added");

How do I add a commit to a message template?

Set a template: Open Settings > Tools > Commit Message Template and enter the desired template or set the path to a template file.

What does a good commit message look like?

General Commit Message Guidelines As a general rule, your messages should start with a single line that's no more than about 50 characters and that describes the changeset concisely, followed by a blank line, followed by a more detailed explanation.


1 Answers

The commit command has an option for reading a commit message from a template:

 -t <file>, --template=<file>
       When editing the commit message, start the editor with the contents
       in the given file. The commit.template configuration variable is often
       used to give this option implicitly to the command. This mechanism can
       be used by projects that want to guide participants with some hints on
       what to write in the message in what order. If the user exits the editor
       without editing the message, the commit is aborted. This has no effect
       when a message is given by other means, e.g. with the -m or -F options.
like image 60
chepner Avatar answered Oct 23 '22 10:10

chepner