kdb
kdb

Reputation: 4416

Missing newline in git log --graph --format=... with file status toggles?

I am trying to get a custom-formatted git log with file status information. However, I ran into a strange little problem with newline positioning.

Apparently, whenever using a --format or --pretty argument, the newline normally inserted after the file status information is omitted. This leads to somewhat hard-to-read output like

>> git log -3 --graph --name-status --format=%h:%s
* eee8e08:Second commit With more details in the body.
|
| M hello.txt
* b6146f7:First commit.
|
| A hello.txt
| A world.txt
* 30cb21f:We start from here. Bla bla bla.

where visually the file-status looks grouped with the wrong commit.

Without the requirement of the --graph option, it could be easily fixed by adding newlines (%n) to the beginning of the format, but wth --graph this just leads to an even more weird look, moving the commit message away from the * denoting the note in the graph.

>> git log -3 --graph --name-status --format=%n%h:%s
*
| 1868195:Second commit With more details in the body.
|
| M hello.txt
*
| 0f03672:First commit.
|
| A hello.txt
| A world.txt
*
| 033f27f:We start from here. Bla bla bla.

The missing newline affects all file-status toggles (e.g. --name-status, --stat, --numstat).

For reference, without formatting commands the verbose message has better newline positioning,

>> git log -3 --graph --name-status
* commit eee8e08d3c892e96228844bcdc6324dc895041af
| Author: me <[email protected]>
| Date:   Wed Nov 22 16:26:58 2017 +0100
|
|     Second commit
|     With more details in the body.
|
| M hello.txt
|
* commit b6146f70b3406508f5b1300c8cda6fd954d3eadd
| Author: me <[email protected]>
| Date:   Wed Nov 22 16:26:58 2017 +0100
|
|     First commit.
|
| A hello.txt
| A world.txt
|
* commit 30cb21f8aba82b30a2f780165533b477cb4555f9
| Author: me <[email protected]>
| Date:   Wed Nov 22 16:26:58 2017 +0100
|
|     We start from here.
|     Bla bla bla.

which makses the grouping of message, header and file-status more clear.

Is there some method to get the file-status information into custom log formats, without missing the newline separating it from the previous commit?


For reference, the output was created in a test repository with a script https://pastebin.com/exLswmeR

Upvotes: 0

Views: 322

Answers (1)

barnski
barnski

Reputation: 1732

This should do the job: git log -3 --graph --name-status --pretty='format:%h:%s%n'

By default in your formatting git is using tformat I guess. See https://git-scm.com/docs/git-log. By setting it to format the new line is added as normal.

I think it changes to tformat because of this(from git doc):

In addition, any unrecognized string that has a % in it is interpreted
as if it has tformat: in front of it. For example, these two are
equivalent:
$ git log -2 --pretty=tformat:%h 4da45bef
$ git log -2 --pretty=%h 4da45bef

Upvotes: 2

Related Questions