在git标记消息中使用多行变量并保留换行符

xfyts7mz  于 2022-11-20  发布在  Git
关注(0)|答案(1)|浏览(137)

我有一个多行变量$foo,我想用它来标记我的最新提交。我希望这些换行符能在git(/github)中显示出来。我试过了

git tag -a v$MAJVER.$MINVER.$PATVER.$HOTVER -m $"$foo"

我怎样才能使它(通过bash),使线断裂生存的推动?

s3fp2yjn

s3fp2yjn1#

只要使用简单的双引号就行了。如果这样不起作用,那就是值中的某个东西。
如果你关心的是提交的输出,那只是一个报告。
去看看实际的日志。

$: ls -l
total 4
-rwxr-xr-x 1 P2759474 1049089 474 Nov  2 14:22 tst

$: mv tst new
$: git status
On branch tst
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        deleted:    tst

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        new

no changes added to commit (use "git add" and/or "git commit -a")

$: foo="
    testing
    multiline
    git
    commit
    message
"

$: git add .
warning: LF will be replaced by CRLF in new.
The file will have its original line endings in your working directory

$: git commit -m "$foo" # keeps newlines, but shows without them
[tst 74428e6]     testing     multiline     git     commit     message
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename tst => new (100%)

$: git log -1
commit 74428e60d830c417ded3ad2c331f02e73319b862 (HEAD -> tst)
Author: Paul Hodges <paul.hodges@redacted.com>
Date:   Thu Nov 3 10:20:33 2022 -0500

        testing
        multiline
        git
        commit
        message

这同样适用于标记,但您必须知道如何将数据恢复出来。

$: git tag -a example -m "$foo"

$: git tag -l
example

$: git tag -n
example             testing

$: git tag -n99
example             testing
        multiline
        git
        commit
        message

你必须告诉它你愿意让它显示多少行信息。默认值是1。

相关问题