如何提供准备好的git提交消息?

VoY*_*VoY 11 git shell scripting

按照惯例,我在git中创建我的故事分支,在其中包含Jira问题ID,例如FOO-1001.我有一个脚本为我做这个.现在,我准备了另一个从Jira API获取FOO-1001标题的脚本.我想在输入时实现:

$ git commit
Run Code Online (Sandbox Code Playgroud)

我的编辑器预先填写了以下内容:

BUGFIX: FOO-1001 Some sample issue title downloaded using my script
Run Code Online (Sandbox Code Playgroud)

使用我描述的脚本实现此目的的最简单方法是什么?我的想法是以某种方式将提交消息格式化为文件,以便git可以找到它并将其用作默认值.一种方法似乎是使用prepare-commit-msghook,但我更喜欢使用独立脚本实现我的目标,没有任何配置.git(这样我的同事可以轻松地重用它).

che*_*ner 16

commit命令有一个从模板中读取提交消息的选项:

 -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.
Run Code Online (Sandbox Code Playgroud)


Ale*_*fee 5

还有-F

   -F <file>, --file=<file>
       Take the commit message from the given file. Use - to read the message from the standard input.
Run Code Online (Sandbox Code Playgroud)