如何在git标签消息中包含换行符 [英] How to include newline characters in git tag messages

查看:415
本文介绍了如何在git标签消息中包含换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在git中标记版本化代码时,我喜欢在标记消息中使用项目符号。



这可以通过带注释的标记轻松完成:

  git tag -a v1.0.0 

*更改编号1
*更改编号2

#写一个标签消息

然而,如果我尝试与-m选项相同的标记,标记消息不是我所期望的:

  git tag -a v1.0.0 -m *更改编号1 \\\
*更改编号2

git show v1.0.0

...

*更改编号1 \\ n *更改编号2
....

'\\\
'是字面解释为字符'\'和'n'而不是换行符。我想使用 -m 选项,以便自动化标记过程。

包含使用 git tag -m 选项的实际换行符?

解决方案

最接近的解决方案是使用多个 -m 选项,每行一个。例如:

  git tag -a v1.0.0 -m*更改数字1-m*更改数字2 

来自 git-tag手册页

  -m< msg> 
使用给定的标签消息(而不是提示)。如果给出多个
-m选项,则它们的值将连接为单独的
段落。 (...)

更新:检查从命令行添加换行符到git commit -m更多基于shell的解决方案。


When I tag versioned code in git, I like using bullet points in the tag message.

This can easily be done with annotated tags:

git tag -a v1.0.0

* Change number 1
* Change number 2
#
# Write a tag message
#

However, if I attempt the same tag with the -m option, the tag message is not what I expect:

git tag -a v1.0.0 -m "* Change number 1\n* Change number 2"

git show v1.0.0

...

* Change number 1\n* Change number 2
....

The '\n' was interpreted literally as the characters '\' and 'n' instead of a newline. I want to use the -m option so that I can automate the tagging process.

Is there any way to include actual newline characters using git tag with the -m option?

解决方案

The closest solution I found is to use multiple -m options, one for each line. For example:

git tag -a v1.0.0 -m "* Change number 1" -m "* Change number 2"

from git-tag man page:

-m <msg>
   Use the given tag message (instead of prompting). If multiple
   -m options are given, their values are concatenated as separate
   paragraphs. (...)

UPDATE: Check "Add line break to git commit -m from command line" for more shell-based solutions.

这篇关于如何在git标签消息中包含换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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