有没有办法准备git标签消息?

时间:2013-08-21 06:40:33

标签: git git-tag

在git中添加新标签时,我希望在我的$ EDITOR启动之前自动修改默认(空)标签消息 - 类似于git允许通过prepare-commit-msg挂钩准备提交消息的方式

例如:

git tag -s v1.2.3

应该使用预先填写的内容打开我的编辑器:

Release v1.2.3:

  * Dynamically generated message 1

  * Dynamically generated message 2

Default standard text.

#
# Write a tag message
# Lines starting with '#' will be ignored

有没有办法实现这个目标?不幸的是,prepare-commit-msg挂钩不适用于标记消息。 (或者这个,或者我太笨了,无法知道如何去做。)

2 个答案:

答案 0 :(得分:4)

您可以创建一个别名,该别名首先使用所需内容填充临时文件,然后使用选项git tag / -F <file>运行--file=<file>,以将临时文件的内容提供给代码信息。从理论上讲,这样的事情:

[alias]
    tag-prepare = !~/bin/prepare_file.sh && git tag --file="/home/user/temp/temp.txt"

然后您可以使用git tag-prepare v1.2.3调用它。

请注意,prepare_file.sh脚本需要创建整个标记消息,因为--file选项不再打开编辑器来编辑内容,只需要w / e在提供的文件中用它作为信息。

答案 1 :(得分:0)

您可以这样做

message="A header line

A body line...
Other lines...

Final line...
"
git tag --annotate --message "${message}" --edit 0.8.0

它将开始创建标签并打开编辑器。就我而言,vimenter image description here