{"thread":{"id":"64901","subject":"[BUG] git log --graph --pretty=format misplaces graph characters when -p given","startedAt":"2026-02-02T16:21:20Z","lastAt":"2026-02-02T20:49:39Z","messageCount":4,"participants":["lolligerhans@gmx.de","Pushkar Singh","D. Ben Knoble","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"534980","messageId":"trinity-ed0884d3-098e-44be-aa1a-a96f664ce7ca-1770049279182@trinity-msg-rest-gmx-gmx-live-5dd78c558c-fv4g4","threadId":"64901","inReplyTo":null,"subject":"[BUG] git log --graph --pretty=format misplaces graph characters when -p given","fromName":"","fromEmail":"lolligerhans@gmx.de","sentAt":"2026-02-02T16:21:19Z","receivedAt":"2026-02-02T16:21:20Z","isPatch":false,"sender":{"key":"lolligerhans@gmx.de","avatar":null},"body":"Hello,\n\nGit can pretty-print a commit graph with git log --graph and a custom --pretty\nformat. I alias some uses of git log --graph --pretty, to which I then want to\nmanually add \"-p\" upon invocation.\n\nWhen using the working command\n    git log --graph --pretty='format:%h'\nand appending \"-p/--patch\", the output appears erroneous:\n    git log --graph --pretty='format:%h' -p                                 (1)\n\nExpected output:\n      1 !    * d0c34d4\n      2      | diff --git a/git-bugreport-2026-02-02-1427.txt b/git-bugreport-2026-02-02-1427.txt\n      3      | index 5a83af1..2740fd4 100644\n      4      | --- a/git-bugreport-2026-02-02-1427.txt\n      5      | +++ b/git-bugreport-2026-02-02-1427.txt\n      6      | @@ -1,22 +1,53 @@\n      7      |  Some context-before line\n      8      | -Some removed line\n    ---      | ...\n    101      | +Some added line\n    102      |  Some context-after line\n    103 !    | \n    104 !    * 28299b2\n    105      | diff --git a/git-bugreport-2026-02-02-1427.txt b/git-bugreport-2026-02-02-1427.txt\n    106      | new file mode 100644\n    107      | index 0000000..5a83af1\n    ---      | ...\n\nActual output, shortened, with line numbers:\n      1 !    * d0c34d4| \n      2      | diff --git a/git-bugreport-2026-02-02-1427.txt b/git-bugreport-2026-02-02-1427.txt\n      3      | index 5a83af1..2740fd4 100644\n      4      | --- a/git-bugreport-2026-02-02-1427.txt\n      5      | +++ b/git-bugreport-2026-02-02-1427.txt\n      6      | @@ -1,22 +1,53 @@\n      7      |  Some context-before line\n      8      | -Some removed line\n    ---      | ...\n    101      | +Some added line\n    102      |  Some context-after line\n    103 !    \n    104 !    * 28299b2| \n    105      | diff --git a/git-bugreport-2026-02-02-1427.txt b/git-bugreport-2026-02-02-1427.txt\n    106      | new file mode 100644\n    107      | index 0000000..5a83af1\n    ---      | ...\n\nIn the actual output, note the trailing \"| \" sequences in lines {1, 104} and the\nmissing graph character in line 103. I believe the sequence in line 1 belongs to\nline 103.\n\nThe actual output looks as if intended to be:\n    <asterisk> <format_string>                    <\\n> <diff> <\\n> <graph_characters> <\\n>\nbut is in the wrong order accidentally:\n    <asterisk> <format_string> <graph_characters> <\\n> <diff> <\\n>                    <\\n>\nwhere the graph_characters \"| \" are misplaced.\n\nNote: I present the reordering of the offending parts as expected, but it may be\nmore reasonable to expect both not to exist. I.e., no trailing \"| \" in line 1\nand no line 103 entirely.\n\nThere are workarounds that hide this problem, with drawbacks. These workarounds\nkeep the graph is visually intact, but their output may still differ from what\nwas originally intended:\n- Workaround: using \"=tformat:\" instead of \"=format:\".\n    But: The diff is visually separated apart from the commit it belongs to and\n    next to the subsequent commit. I.e., it appears something is still\n    misplaced, and the result is better only coincidentally. Compare to\n        git log --graph --oneline -p\n    which does not use any separation for a --patch.\n- Workaround: using \"%h%n\" instead of \"%h\".\n    Ending the format string with explicit newline curiously fixes the display\n    with --patch, but introduces many obsolete lines when used without --patch,\n    especially for one-line format strings.\n\nWhat did you do before the bug happened? (Steps to reproduce your issue)\n\n    1. Ensure at least 2 commits exist. Makes --graph meaningful.\n    2. Run the offending command (1):\n        git log --graph --pretty='format:%h' -p                             (1)\n\n    Alternatively with shorter output:\n        git log --graph --pretty='format:%h' -p --color=always | head -3\n\nWhat did you expect to happen? (Expected behavior)\n\n    The characters forming edges/vertices of the visual graph are printed at the\n    beginning of lines, horizontally left of the other log contents.\n\nWhat happened instead? (Actual behavior)\n\n    Some characters semantically belonging to the visual graph are printed at\n    the end of the line, after the format string.\n\nWhat's different between what you expected and what actually happened?\n\n    The actual output does not visually form the expected graph. It appears that\n    outputs are printed in unintended order.\n\nAnything else you want to add:\n\n    I did not check if \"--format\" instead of \"--pretty=format:\" behaves\n    identically.\n\n    I grepped for \"pretty\" in the commits v2.51.0..origin/next and the problem\n    appears not to be addressed yet.\n\n    With more branches and colors, the visuals are consistent with what\n    I describe above.\n\n    I do not know what is going on here:\n        - Using format string \"%s%n%b\" appears to work fine.\n        - Using format string \"%s  %b\" does not work, but problems start only at\n          the second commit, not first.\n        - Using format string \"  %n%s\" does not work.\n\n\n[System Info]\ngit version:\ngit version 2.51.0\n$SHELL (typically, interactive shell): /bin/bash\n\n[Enabled Hooks]\nnot run from a git repository - no hooks to show\n\n"},{"id":"534988","messageId":"CALE2CrR5MS=LmXGYW8VbN_trLzMf1tk3BEkh3wv=hju9AWQbeg@mail.gmail.com","threadId":"64901","inReplyTo":"trinity-ed0884d3-098e-44be-aa1a-a96f664ce7ca-1770049279182@trinity-msg-rest-gmx-gmx-live-5dd78c558c-fv4g4","subject":"Re: [BUG] git log --graph --pretty=format misplaces graph characters when -p given","fromName":"Pushkar Singh","fromEmail":"pushkarkumarsingh1970@gmail.com","sentAt":"2026-02-02T17:27:49Z","receivedAt":"2026-02-02T17:28:01Z","isPatch":false,"sender":{"key":"pushkarkumarsingh1970@gmail.com","avatar":"https://avatars.githubusercontent.com/u/173247767?v=4"},"body":"Hi,\n\nI can reproduce this on Git 2.43.0.\n\nMinimal steps:\n\n    git init\n    echo first >test.txt\n    git add test.txt\n    git commit -m \"first\"\n\n    echo second >>test.txt\n    git add test.txt\n    git commit -m \"second\"\n\nThen:\n\n    git log --graph --pretty='format:%h' -p\n\nI see the same trailing \"|\" after the commit hash:\n\n    * 0139218|\n    | diff --git ...\n\nSo the graph character appears on the wrong line, matching your report.\n\nTested on WSL/Linux.\n\nThanks,\nPushkar\n"},{"id":"535009","messageId":"CALnO6CCqwnTcQWSUBPV+o3OO=sMZJjj6jRuMNnBjV3F-dYx+0w@mail.gmail.com","threadId":"64901","inReplyTo":"trinity-ed0884d3-098e-44be-aa1a-a96f664ce7ca-1770049279182@trinity-msg-rest-gmx-gmx-live-5dd78c558c-fv4g4","subject":"Re: [BUG] git log --graph --pretty=format misplaces graph characters when -p given","fromName":"D. Ben Knoble","fromEmail":"ben.knoble@gmail.com","sentAt":"2026-02-02T20:27:22Z","receivedAt":"2026-02-02T20:27:34Z","isPatch":false,"sender":{"key":"ben.knoble@gmail.com","avatar":"https://avatars.githubusercontent.com/u/22802209?v=4"},"body":"On Mon, Feb 2, 2026 at 11:22 AM <lolligerhans@gmx.de> wrote:\n>\n> Hello,\n>\n> Git can pretty-print a commit graph with git log --graph and a custom --pretty\n> format. I alias some uses of git log --graph --pretty, to which I then want to\n> manually add \"-p\" upon invocation.\n>\n> When using the working command\n>     git log --graph --pretty='format:%h'\n> and appending \"-p/--patch\", the output appears erroneous:\n>     git log --graph --pretty='format:%h' -p                                 (1)\n>\n> Expected output:\n>       1 !    * d0c34d4\n>       2      | diff --git a/git-bugreport-2026-02-02-1427.txt b/git-bugreport-2026-02-02-1427.txt\n>       3      | index 5a83af1..2740fd4 100644\n>       4      | --- a/git-bugreport-2026-02-02-1427.txt\n>       5      | +++ b/git-bugreport-2026-02-02-1427.txt\n>       6      | @@ -1,22 +1,53 @@\n>       7      |  Some context-before line\n>       8      | -Some removed line\n>     ---      | ...\n>     101      | +Some added line\n>     102      |  Some context-after line\n>     103 !    |\n>     104 !    * 28299b2\n>     105      | diff --git a/git-bugreport-2026-02-02-1427.txt b/git-bugreport-2026-02-02-1427.txt\n>     106      | new file mode 100644\n>     107      | index 0000000..5a83af1\n>     ---      | ...\n>\n> Actual output, shortened, with line numbers:\n>       1 !    * d0c34d4|\n>       2      | diff --git a/git-bugreport-2026-02-02-1427.txt b/git-bugreport-2026-02-02-1427.txt\n>       3      | index 5a83af1..2740fd4 100644\n>       4      | --- a/git-bugreport-2026-02-02-1427.txt\n>       5      | +++ b/git-bugreport-2026-02-02-1427.txt\n>       6      | @@ -1,22 +1,53 @@\n>       7      |  Some context-before line\n>       8      | -Some removed line\n>     ---      | ...\n>     101      | +Some added line\n>     102      |  Some context-after line\n>     103 !\n>     104 !    * 28299b2|\n>     105      | diff --git a/git-bugreport-2026-02-02-1427.txt b/git-bugreport-2026-02-02-1427.txt\n>     106      | new file mode 100644\n>     107      | index 0000000..5a83af1\n>     ---      | ...\n>\n> In the actual output, note the trailing \"| \" sequences in lines {1, 104} and the\n> missing graph character in line 103. I believe the sequence in line 1 belongs to\n> line 103.\n\nYep. I think this is because format:%h doesn't add a newline by\ndefault. With tformat:%h or format:%h%n, the issue goes away. (See\n\"git help log\" under \"tformat:\"—this is probably what you want in\norder to get \"oneline\"-style format.)\n\n-- \nD. Ben Knoble\n"},{"id":"535011","messageId":"xmqqo6m6yiov.fsf@gitster.g","threadId":"64901","inReplyTo":"CALnO6CCqwnTcQWSUBPV+o3OO=sMZJjj6jRuMNnBjV3F-dYx+0w@mail.gmail.com","subject":"Re: [BUG] git log --graph --pretty=format misplaces graph characters when -p given","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-02-02T20:49:36Z","receivedAt":"2026-02-02T20:49:39Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"D. Ben Knoble\" <ben.knoble@gmail.com> writes:\n\n> On Mon, Feb 2, 2026 at 11:22 AM <lolligerhans@gmx.de> wrote:\n>>\n>> Hello,\n>>\n>> Git can pretty-print a commit graph with git log --graph and a custom --pretty\n>> format. I alias some uses of git log --graph --pretty, to which I then want to\n>> manually add \"-p\" upon invocation.\n>> ...\n> Yep. I think this is because format:%h doesn't add a newline by\n> default. With tformat:%h or format:%h%n, the issue goes away. (See\n> \"git help log\" under \"tformat:\"—this is probably what you want in\n> order to get \"oneline\"-style format.)\n\nFWIW, \"git log --pretty=tformat:<whatever>\" has a handy short-hand\nthat is \"git log --format=<whatever>\" ;-)\n"}]}