简体   繁体   中英

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

I am learning 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:

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@gmail.com\\nInfo: Merge pull request #563 from nunit/issue-562

Also I read this before :

Escaping strings isn't Git's job; git log doesn't have anything that'll help you do that.

So, is it impossible for escape chars too?

You are mixing two different kind of things. From man git :

The format: format allows you to specify which information you want to show. It works a little bit like printf format, with the notable exception that you get a newline with %n instead of \\n.

Answer: use %n

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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