12

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

$ git commit

我的编辑器打开预填充以下内容:

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

使用我描述的脚本来实现这一目标的最简单方法是什么?我的想法是以某种方式将提交消息格式化为一个文件,以便 git 可以找到它并作为默认值使用。一种方法似乎是使用prepare-commit-msg钩子,但我更愿意使用独立脚本来实现我的目标,而不需要任何配置.git(以便我的同事可以轻松地重用它)。

4

2 回答 2

17

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.
于 2013-03-21T20:58:46.697 回答
5

还有-F

   -F <file>, --file=<file>
       Take the commit message from the given file. Use - to read the message from the standard input.
于 2014-06-17T11:45:25.040 回答