From: lolligerhans@gmx.de Date: Mon, 02 Feb 2026 16:21:19 GMT Subject: [BUG] git log --graph --pretty=format misplaces graph characters when -p given Message-ID: 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. The actual output looks as if intended to be: <\n> <\n> <\n> but is in the wrong order accidentally: <\n> <\n> <\n> where the graph_characters "| " are misplaced. Note: I present the reordering of the offending parts as expected, but it may be more reasonable to expect both not to exist. I.e., no trailing "| " in line 1 and no line 103 entirely. There are workarounds that hide this problem, with drawbacks. These workarounds keep the graph is visually intact, but their output may still differ from what was originally intended: - Workaround: using "=tformat:" instead of "=format:". But: The diff is visually separated apart from the commit it belongs to and next to the subsequent commit. I.e., it appears something is still misplaced, and the result is better only coincidentally. Compare to git log --graph --oneline -p which does not use any separation for a --patch. - Workaround: using "%h%n" instead of "%h". Ending the format string with explicit newline curiously fixes the display with --patch, but introduces many obsolete lines when used without --patch, especially for one-line format strings. What did you do before the bug happened? (Steps to reproduce your issue) 1. Ensure at least 2 commits exist. Makes --graph meaningful. 2. Run the offending command (1): git log --graph --pretty='format:%h' -p (1) Alternatively with shorter output: git log --graph --pretty='format:%h' -p --color=always | head -3 What did you expect to happen? (Expected behavior) The characters forming edges/vertices of the visual graph are printed at the beginning of lines, horizontally left of the other log contents. What happened instead? (Actual behavior) Some characters semantically belonging to the visual graph are printed at the end of the line, after the format string. What's different between what you expected and what actually happened? The actual output does not visually form the expected graph. It appears that outputs are printed in unintended order. Anything else you want to add: I did not check if "--format" instead of "--pretty=format:" behaves identically. I grepped for "pretty" in the commits v2.51.0..origin/next and the problem appears not to be addressed yet. With more branches and colors, the visuals are consistent with what I describe above. I do not know what is going on here: - Using format string "%s%n%b" appears to work fine. - Using format string "%s %b" does not work, but problems start only at the second commit, not first. - Using format string " %n%s" does not work. [System Info] git version: git version 2.51.0 $SHELL (typically, interactive shell): /bin/bash [Enabled Hooks] not run from a git repository - no hooks to show