Is there a way to prepare git tag messages?

青春壹個敷衍的年華 提交于 2019-12-07 06:40:23

问题


When adding a new tag in git, I would like to automatically modify the default (empty) tag message before my $EDITOR fires up—similar to the way that git allows to prepare commit messages via the prepare-commit-msg hook.

For example:

git tag -s v1.2.3

should open my editor with pre-filled contents like this:

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

Is there any way to achieve this? Unfortunately, the prepare-commit-msg hook doesn’t work with tag messages. (Either this, or I was too dumb to find out how to do it.)


回答1:


You could create an alias which would first populate a temp file with the desired content and then run git tag with the option -F <file>/--file=<file> to feed the temp file's content into the tag message. Theoretically, something like this:

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

You would then call it with git tag-prepare v1.2.3.

Note that the prepare_file.sh script needs to create the entire tag message because the --file option does not open the editor to edit the content anymore, it only takes w/e is in the provided file and uses that as the message.




回答2:


You can do something like this

message="A header line

A body line...
Other lines...

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

It will start tag creation and opens an editor. In my case vim:



来源:https://stackoverflow.com/questions/18350447/is-there-a-way-to-prepare-git-tag-messages

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!