在我的Mac上,我通过以下命令提交git信息。我希望git信息显示换行符,所以我将\n添加到字符串中。但它似乎不起作用,git也不会按照\n符号包装行:
commit_log1="111\n"
commit_log2="222"
git commit -m "${commit_log1}${commit_log2}"

有谁知道如何根据字符串中的符号制作git包线吗?
发布于 2022-09-22 14:52:56
这是为我工作的:
git commit -m "$( echo -e $commit_log1$commit_log2 )"至少在巴什。
发布于 2022-09-22 13:55:16
这很可能是shell问题,而不是git问题:
# zsh :
$ echo "foo\nbar"
foo
bar
# bash :
$ echo "foo\nbar"
foo\nbar如果您使用bash运行您在问题中显示的命令(可能是从以#!/bin/bash开头的脚本?)您将有一个litteral \n,而不是git消息中的换行符。
如果您想使用bash,可以选择向提交消息添加换行符的多种方式之一:
(bash)使用$'...'语法(参见this question):
# bash :
$ echo $'foo\nbar'
foo
bar
$ commit_log1=$'111\n'
$ commit_log2="222"
$ git commit -m "${commit_log1}${commit_log2}"(bash)字符串litteral中的普通旧换行符:
$ commit_log1="111"
$ commit_log2="222"
$ git commit -m "${commit_log1}
${commit_log2}"(git)使用git,从stdin或文件读取提交消息:
# from stdin
$ (echo 111; echo 222) | git commit -F -
# from a file
$ git commit -F /tmp/mycommitmessage(git)提供几次-m选项:
$ git commit -m "111" -m "222"..。
https://stackoverflow.com/questions/73815043
复制相似问题