Git commit message messed up when stored in a variable [duplicate]

一个人想着一个人 提交于 2019-12-24 01:17:43

问题


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?


回答1:


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" 


来源:https://stackoverflow.com/questions/47784319/git-commit-message-messed-up-when-stored-in-a-variable

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