Git Mailing List Archive mirror
 help / color / mirror / Atom feed
From: Javier Mora <cousteaulecommandant@gmail.com>
To: git@vger.kernel.org
Subject: Commit graph not using minimal number of columns
Date: Wed, 26 Apr 2023 00:39:01 +0100	[thread overview]
Message-ID: <CAH1-q0hReZoDWmXo7St10Dk6uc+6ZUQSxqvu1cJ7w3r7ftR9PQ@mail.gmail.com> (raw)

This is something that annoys me a lot whenever I'm maintaining a git
repo with two branches - a main development one and a "fork" or
alteration of the main one, which periodically merges changes from the
main one while at the same time maintaining some additional feature.

When I display the commit graph with `git log --graph` or `gitk`, this
type of graph shows up really nice, with two parallel "tracks"
corresponding to the two branches with periodic merges between them.
However, if for some reason I merge an early version of the main
branch when there's already a newer commit in that branch, then the
entire graph becomes an ugly mess that uses a lot of horizontal space,
and I lose the visual representation of "two parallel tracks".
This seems to be due to git relying on commit dates to decide which
commit goes first, rather than relying solely on topological order.

Example:
```
mkdir TEST_git
cd TEST_git
git init -b main

touch A
git add A
git commit -m 'First commit'

git switch -c fork
touch Z
git add Z
git commit -m 'Introduced feature Z'

for i in B C D E F; do
    git switch main
    touch "$i"
    git add "$i"
    git commit -m "Add $i"
    git switch fork
    git merge --no-edit main
done

git log --all --decorate --oneline --graph
# ^ displays a pretty "two-track" graph

git switch main
for i in G H; do
    touch "$i"
    git add "$i"
    git commit -m "Add $i"
done
git switch fork
git merge --no-edit main~1

git log --all --decorate --oneline --graph
# ^ displays a complete mess that doesn't resemble two tracks
```

This seems to happen because commit H was created after G but before
merging G into `fork`, and can be mitigated by updating the committer
date of H so that it is newer than the merge of G into `fork`, but
that is not always an option.  It also seems to go away after merging
H into `fork`, but that won't work if H is part of a
temporary/abandoned branch I don't plan to merge yet.  And I found
that calling `git log main --all ...` somehow fixes the graph as well.
In these cases, the option `--date-order` actually seems to yield
better graphs than the default (`--topo-order`), but that option is
not ideal, since it may interleave commits from two separate branches,
whereas the default will group commits "semantically".

What do you think?  Do you agree that this sort of thing looks
annoying?  Do you think there might be a way to solve this kind of
issue by improving the graph generation algorithm, so that it
minimizes the number of columns in the graph (for example, preferring
to display merge commits as late as possible)?  Or is this actually
intentional, because the developers consider that in this sort of
situation it would be preferable to group all the merges together?

             reply	other threads:[~2023-04-25 23:39 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-25 23:39 Javier Mora [this message]
2023-04-25 23:50 ` Commit graph not using minimal number of columns Junio C Hamano
2023-04-26 10:45   ` Derrick Stolee
2023-04-26 16:10     ` Junio C Hamano
2023-04-26 17:35       ` Derrick Stolee
2023-04-26 17:43         ` Junio C Hamano
2023-04-27 13:02           ` Derrick Stolee
2023-04-27 18:24             ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAH1-q0hReZoDWmXo7St10Dk6uc+6ZUQSxqvu1cJ7w3r7ftR9PQ@mail.gmail.com \
    --to=cousteaulecommandant@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).