git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [BUG] git log --graph --pretty=format misplaces graph characters when -p given

From
D. Ben Knoble <ben.knoble@gmail.com>
Date
Feb 2, 2026, 20:27 UTC
Message-ID
<CALnO6CCqwnTcQWSUBPV+o3OO=sMZJjj6jRuMNnBjV3F-dYx+0w@mail.gmail.com>
In-Reply-To
<trinity-ed0884d3-098e-44be-aa1a-a96f664ce7ca-1770049279182@trinity-msg-rest-gmx-gmx-live-5dd78c558c-fv4g4>
On Mon, Feb 2, 2026 at 11:22 AM <lolligerhans@gmx.de> wrote:
Show 53 quoted lines
>
> Hello,
>
> Git can pretty-print a commit graph with git log --graph and a custom --pretty
> format. I alias some uses of git log --graph --pretty, to which I then want to
> manually add "-p" upon invocation.
>
> When using the working command
>     git log --graph --pretty='format:%h'
> and appending "-p/--patch", the output appears erroneous:
>     git log --graph --pretty='format:%h' -p                                 (1)
>
> Expected output:
>       1 !    * d0c34d4
>       2      | diff --git a/git-bugreport-2026-02-02-1427.txt b/git-bugreport-2026-02-02-1427.txt
>       3      | index 5a83af1..2740fd4 100644
>       4      | --- a/git-bugreport-2026-02-02-1427.txt
>       5      | +++ b/git-bugreport-2026-02-02-1427.txt
>       6      | @@ -1,22 +1,53 @@
>       7      |  Some context-before line
>       8      | -Some removed line
>     ---      | ...
>     101      | +Some added line
>     102      |  Some context-after line
>     103 !    |
>     104 !    * 28299b2
>     105      | diff --git a/git-bugreport-2026-02-02-1427.txt b/git-bugreport-2026-02-02-1427.txt
>     106      | new file mode 100644
>     107      | index 0000000..5a83af1
>     ---      | ...
>
> Actual output, shortened, with line numbers:
>       1 !    * d0c34d4|
>       2      | diff --git a/git-bugreport-2026-02-02-1427.txt b/git-bugreport-2026-02-02-1427.txt
>       3      | index 5a83af1..2740fd4 100644
>       4      | --- a/git-bugreport-2026-02-02-1427.txt
>       5      | +++ b/git-bugreport-2026-02-02-1427.txt
>       6      | @@ -1,22 +1,53 @@
>       7      |  Some context-before line
>       8      | -Some removed line
>     ---      | ...
>     101      | +Some added line
>     102      |  Some context-after line
>     103 !
>     104 !    * 28299b2|
>     105      | diff --git a/git-bugreport-2026-02-02-1427.txt b/git-bugreport-2026-02-02-1427.txt
>     106      | new file mode 100644
>     107      | index 0000000..5a83af1
>     ---      | ...
>
> In the actual output, note the trailing "| " sequences in lines {1, 104} and the
> missing graph character in line 103. I believe the sequence in line 1 belongs to
> line 103.

Yep. I think this is because format:%h doesn't add a newline by default. With tformat:%h or format:%h%n, the issue goes away. (See "git help log" under "tformat:"—this is probably what you want in order to get "oneline"-style format.)

-- 
D. Ben Knoble
Previous: Pushkar SinghNext: Junio C Hamano
Message 3 of 4 in “[BUG] git log --graph --pretty=format misplaces graph characters when -p given”
  1. lolligerhans@gmx.deFeb 2, 2026
  2. Pushkar SinghFeb 2, 2026
  3. D. Ben KnobleFeb 2, 2026
  4. Junio C HamanoFeb 2, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.