Git:在自定义日志格式中打印一个井号。

huangapple go评论66阅读模式
英文:

Git: Print a hashtag in a custom log format

问题

我如下提供翻译:

如何创建一个自定义日志格式,其中行的开头有一个井号(#)?

我已经在我的git别名中使用破折号获得了我想要的格式:

lpr = log -10 --reverse --format=format:'- %Cgreen  %s%n%Creset%b'

问题显然是#是注释,应该被转义。我找不到如何做到这一点。

最终目标是能够创建Markdown格式的日志消息,其中第一行是标题。

英文:

How can I create a custom log format where the start of the line has a hashtag (#)

I have already the format I want with a dash in my git aliases:

lpr = log -10 --reverse --format=format:'- %Cgreen  %s%n%Creset%b'

The problem clearly is that # is the comment and should be escaped. I don't find how that is done.

The final goal is to be able to create markdown formatted log messages where the first line is a title.

答案1

得分: 1

I just tested the git alias with a #, and it seems to work as expected:

C:\my\repo>git config alias.lpr "log -10 --reverse --format=format:'- %Cgreen  # %s%n%Creset%b'"
C:\my\repo>git lpr

-   # Subject commit 3
Body 3

-   # Subject commit 2
Body 2

-   # Subject commit 1
Body 1

The strong quotes 'log ... # ...' means you do not have to escape the #.

Rendered markdown:

Git:在自定义日志格式中打印一个井号。

Meaning

英文:

I just tested the git alias with a #, and it seems to work as expected:

C:\my\repo>git config alias.lpr "log -10 --reverse --format=format:'- %Cgreen  # %s%n%Creset%b'"
C:\my\repo>git lpr

-   # Subject commit 3
Body 3

-   # Subject commit 2
Body 2

-   # Subject commit 1
Body 1

The strong quotes 'log ... # ...' means you do not have to escape the #.

Rendered markdown:

Git:在自定义日志格式中打印一个井号。

Meaning

huangapple
  • 本文由 发表于 2023年6月22日 14:33:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/76529132.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定