当存储在一个变量中时,Git commit消息会混乱 [英] Git commit message messed up when stored in a variable

查看:116
本文介绍了当存储在一个变量中时,Git commit消息会混乱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Git commit,它有一个摘要,然后是一些描述。所以当我通过 git log --format =%B -n 1< commit> 看到提交信息时,它看起来像这样:



提交摘要行
*提交描述行1
*提交描述行2
*提交描述行3



然而,当我尝试将它存储在一个Bash变量中时,如下所示:

message = $(git log --format =%B -n 1< commit>)



然后我尝试 echo $ message ,我从当前目录中得到与提交消息中的每一行混合的文件夹名称。更重要的是,我甚至没有看到来自提交信息的所有行,只是其中的一部分。因此, $ message 看起来像这样:
$ b 提交摘要行folder1 folder2 folder3提交描述第1行folder1 folder2 folder3提交描述第3行



这种行为有任何解释吗?我只希望 $ message 具有来自完整提交消息的所有行。我甚至不在乎它们是在新行还是在一行中,我只想将所有行存储在字符串变量中。我怎么做到这一点?

解决方案

似乎有点流氓 pathname expansion * 。尝试在你的消息变量周围添加一对引号,你应该很好!

  echo$ message


I have a Git commit, which has a summary, and then some description. So when I see the commit message via git log --format=%B -n 1 <commit>, it looks like this:

Commit Summary Line * Commit Description Line 1 * Commit Description Line 2 * Commit Description Line 3

When I try to store this in a Bash variable, however, thus:

message=$(git log --format=%B -n 1 <commit>)

and then I try to echo $message, I get the folder names from my current directory mixed with each of the lines from the commit message. What's more, I am not even seeing all lines from the commit message, just some of them. So, $message looks something like this:

Commit Summary Line folder1 folder2 folder3 Commit Description Line 1 folder1 folder2 folder3 Commit Description Line 3

Is there any explanation for this behavior? I just want $message to have all lines from the full commit message. I don't even care if they are in new lines or all in one line, I just want all lines stored in a string variable. How do I achieve this?

解决方案

Seems to be a bit of rogue pathname expansion at play here caused by the *. Try adding a pair of quotes around your message variable and you should be good!

echo "$message" 

这篇关于当存储在一个变量中时,Git commit消息会混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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