如何提供准备好的git commit消息? [英] How to provide a prepared git commit message?

查看:77
本文介绍了如何提供准备好的git commit消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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).

推荐答案

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

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.

这篇关于如何提供准备好的git commit消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆