按照惯例,我在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
中没有任何配置(以便我的同事可以轻松地重复使用它)。
答案 0 :(得分: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.
答案 1 :(得分:3)
还有-F
:
-F <file>, --file=<file>
Take the commit message from the given file. Use - to read the message from the standard input.