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

[RFC] Proposal to add a delimiter between unrelated history in git-log --graph --oneline

From
JBJosh Brunton <josh.brunton@proton.me>
Date
Dec 3, 2024, 17:29 UTC
Message-ID
<FNUesYPDfyA16MXr4g9q7vW9OQ6bfbUK1umvVjONQNgEsQJZV5sIvRX9MlHfRILe4-hhINNy59uNjywL4abyJT43JVYjXU0ofUGWKQo0lFA=@proton.me>

Though a relatively rare occurrence, I sometimes find myself working withrepositories that contain 2 un-merged, unrelated histories. In doing so, I've often found myself confused or mistaken due to the way "git-log --oneline --graph" handles unrelated histories: by presenting them as if they were one continuous string of commits.

To create an example of how git-log --oneline --graph presents unmerged unrelated histories, let us use the following minimal reproducible example.

In ~/repos/git-history-1:
* dec7d4c (HEAD -> main, origin/main) History 1 - Add README.md
* 3f25318 History 1 - Add gitignore
In ~/repos/git-history-2:
* (HEAD -> main2, origin/main2) e5698bf History 2 - Add SECURITY.md
* 7260dff History 2 - Add .gitattributes
If both are pushed to ~/git-history-origin, that repo's log (git-log --graph)
looks like:
[...]
|     Add SECURITY.md
|
* commit 7260dff47ffb6233b5f7ccfd62a1be29047d813d
  Author: Josh Brunton <josh.brunton@proton.me>
  Date:   Tue Dec 3 09:57:43 2024 +0000
      Add .gitattributes
* commit dec7d4cab044e37dd340b487a4d1d8b8b0cac867 (HEAD -> main)
| Author: Josh Brunton <josh.brunton@proton.me>
| Date:   Tue Dec 3 09:55:50 2024 +0000
[...]
There is a clear disconnect between commits dec7d4c 7260dff, showing that
they represent 2 unrelated histories. However, passing --oneline as well produces
the following output:
* e5698bf (main2) History 2 - Add SECURITY.md
* 7260dff History 2 - Add .gitattributes
* dec7d4c (HEAD -> main) History 1 - Add README.md
* 3f25318 History 1 - Add gitignore

With this graph, one might be forgiven for the assumption that dec7d4c is the parent of 7260dff, as it would be visually indistinguishable if that were the case and is far more likely than having 2 unmerged, unrelated histories. This can lead to some confusion and/or bad assumptions about the history.

It is not until we merge the 2 histories that git log --oneline --graph shows
any indication at all that those histories were unrelated:
*   15177d2 (HEAD -> main) Merge branch 'main2'
|\
| * e5698bf (main2) History 2 - Add SECURITY.md
| * 7260dff History 2 - Add .gitattributes
* dec7d4c History 1 - Add README.md
* 3f25318 History 1 - Add gitignore

I therefore suggest that a separator line (perhaps a blank line) might be added between unrelated histories which would otherwise seem related in --oneline --graph. In other words, the separator should appear between any 2 consecutive lines where * appears in the same column, where the above line's commit has no parent(s). I believe unrelated histories are clearly represented in other cases.

I have considered that doing so may require that each commit in the log would have to undergo an additional check to see if it has any ancestors. Though I am not knowledgeable on how resource-heavy this operation would be, I am wary that it may pose a significant performance impact. Thus, I suggest that this feature might be opt-in via a config setting named along the lines of log.delimitUnrelatedHistories.

In implementing this proposal, the above unrelated histories would become:
* e5698bf (main2) History 2 - Add SECURITY.md
* 7260dff History 2 - Add .gitattributes
* dec7d4c (HEAD -> main) History 1 - Add README.md
* 3f25318 History 1 - Add gitignore
While if some other factor were to create the same effect of clarifying that
the histories are unrelated, the output would remain unchanged:
* e5698bf (main2) History 2 - Add SECURITY.md
| * 3c3cade (branch3) Add CODEOWNERS
* | 7260dff History 2 - Add .gitattributes
  |
* / dec7d4c (HEAD -> main) History 1 - Add README.md
|/
* 3f25318 History 1 - Add gitignore

Depending on approval here, I am prepared to attempt to implement this feature myself, though would appreciate input from those more knowledgeable about the git codebase and experienced with contributing.

Next: Junio C Hamano
Message 1 of 2 in “[RFC] Proposal to add a delimiter between unrelated history in git-log --graph --oneline”
  1. Josh BruntonDec 3, 2024
  2. Junio C HamanoDec 3, 2024

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.