简体   繁体   English

如何在git log --pretty = format中设置特殊字符?

[英]How can I set special chars in the git log --pretty=format?

I am learning Git. 我正在学习Git。 I wrote the command: 我写了命令:

$ git log --pretty=format:"author: %an, %ae\ncommiter: %cn, %ce\nInfo: %s"

I expected \\n will be interpreted like a new line char: 我希望\\n将被解释为换行符char:

author: CharliePoole, charliepoole@gmail.com
commiter: CharliePoole, charliepoole@gmail.com
Info: Merge pull request #563 from nunit/issue-562

But I get this output: 但是我得到以下输出:

author: CharliePoole, charliepoole@gmail.com\\ncommiter: CharliePoole, 作者:CharliePoole,charliepoole @ gmail.com \\ n提交人:CharliePoole,
charliepoole@gmail.com\\nInfo: Merge pull request #563 from nunit/issue-562 charliepoole@gmail.com \\ n信息:合并来自nunit / issue-562的拉取请求#563

Also I read this before : 此外,我读这之前

Escaping strings isn't Git's job; 转义字符串不是Git的工作; git log doesn't have anything that'll help you do that. git log没有什么可以帮助您做到这一点的。

So, is it impossible for escape chars too? 那么,逃逸字符也是不可能的吗?

You are mixing two different kind of things. 您正在混合两种不同的东西。 From man git : man git

The format: format allows you to specify which information you want to show. 格式:format允许您指定要显示的信息。 It works a little bit like printf format, with the notable exception that you get a newline with %n instead of \\n. 它的工作方式类似于printf格式,但值得注意的例外是您使用%n而不是\\ n换行。

Answer: use %n 答案:使用%n

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM