* [BUG] git log --graph --pretty=format misplaces graph characters when -p given
@ 2026-02-02 16:21 lolligerhans
2026-02-02 17:27 ` Pushkar Singh
2026-02-02 20:27 ` D. Ben Knoble
0 siblings, 2 replies; 4+ messages in thread
From: lolligerhans @ 2026-02-02 16:21 UTC (permalink / raw)
To: git
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:
<asterisk> <format_string> <\n> <diff> <\n> <graph_characters> <\n>
but is in the wrong order accidentally:
<asterisk> <format_string> <graph_characters> <\n> <diff> <\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
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [BUG] git log --graph --pretty=format misplaces graph characters when -p given
2026-02-02 16:21 [BUG] git log --graph --pretty=format misplaces graph characters when -p given lolligerhans
@ 2026-02-02 17:27 ` Pushkar Singh
2026-02-02 20:27 ` D. Ben Knoble
1 sibling, 0 replies; 4+ messages in thread
From: Pushkar Singh @ 2026-02-02 17:27 UTC (permalink / raw)
To: lolligerhans; +Cc: git
Hi,
I can reproduce this on Git 2.43.0.
Minimal steps:
git init
echo first >test.txt
git add test.txt
git commit -m "first"
echo second >>test.txt
git add test.txt
git commit -m "second"
Then:
git log --graph --pretty='format:%h' -p
I see the same trailing "|" after the commit hash:
* 0139218|
| diff --git ...
So the graph character appears on the wrong line, matching your report.
Tested on WSL/Linux.
Thanks,
Pushkar
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [BUG] git log --graph --pretty=format misplaces graph characters when -p given
2026-02-02 16:21 [BUG] git log --graph --pretty=format misplaces graph characters when -p given lolligerhans
2026-02-02 17:27 ` Pushkar Singh
@ 2026-02-02 20:27 ` D. Ben Knoble
2026-02-02 20:49 ` Junio C Hamano
1 sibling, 1 reply; 4+ messages in thread
From: D. Ben Knoble @ 2026-02-02 20:27 UTC (permalink / raw)
To: lolligerhans; +Cc: git, Pushkar Singh
On Mon, Feb 2, 2026 at 11:22 AM <lolligerhans@gmx.de> wrote:
>
> 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
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [BUG] git log --graph --pretty=format misplaces graph characters when -p given
2026-02-02 20:27 ` D. Ben Knoble
@ 2026-02-02 20:49 ` Junio C Hamano
0 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2026-02-02 20:49 UTC (permalink / raw)
To: D. Ben Knoble; +Cc: lolligerhans, git, Pushkar Singh
"D. Ben Knoble" <ben.knoble@gmail.com> writes:
> On Mon, Feb 2, 2026 at 11:22 AM <lolligerhans@gmx.de> wrote:
>>
>> 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.
>> ...
> 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.)
FWIW, "git log --pretty=tformat:<whatever>" has a handy short-hand
that is "git log --format=<whatever>" ;-)
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-02-02 20:49 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-02 16:21 [BUG] git log --graph --pretty=format misplaces graph characters when -p given lolligerhans
2026-02-02 17:27 ` Pushkar Singh
2026-02-02 20:27 ` D. Ben Knoble
2026-02-02 20:49 ` Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox