threads / discuss / 40793

git log --merges doesn't show commits as expected

Subject: git log --merges doesn't show commits as expected

## tl;dr

2 messages between Nov 13, 2015 and Nov 13, 2015.

replies: 1people: 2as markdown or json

Dominik Rauch· Nov 13, 2015, 16:21 UTC · lore
Hello!
 
(This is my first post to this mailing list and I couldn't find a FAQ section - please excuse me, if I haven't followed all the established posting guidelines yet.)
I have the following repository tree:
C
|\
| B
| /
A

Commit A: Parents=(). Initial commit. Contains file foo with content "ABC". Commit B: Parents=(A). Represents a commit on some feature branch. Contains file foo with content "XYZ". Commit C: Parents=(A, B). Represents a merge commit of a feature branch back to the main branch. Contains file foo with content "XYZ".

I expected "git log --merges foo" to show C, however, the log is empty! Specifying "--full-history" results in the correct history, therefore I assume, I misunderstand Git's default history simplification algorithm. Unfortunately, the example in the Git docs at [1] does not contain the very same situation (although it is probably one of the most common situations...).
Does anybody know why I don't see the log output I expect? I'm confused...even if the log output is correct, I don't think it follows the principle of least surprise...
Side note: specifying "--first-parent" also results in commit C being shown.

Best regards, Dominik

PS: This is a cross post of [2], somebody noted it could be a bug, which is why I decided to post to this mailing list.

[1] https://git-scm.com/docs/git-log#_history_simplification [2] http://stackoverflow.com/q/33695763/

Jeff King· Nov 13, 2015, 22:35 UTC · re: Dominik Rauch · lore

Re: git log --merges doesn't show commits as expected

On Fri, Nov 13, 2015 at 04:21:36PM +0000, Dominik Rauch wrote:
> (This is my first post to this mailing list and I couldn't find a FAQ
> section - please excuse me, if I haven't followed all the established
> posting guidelines yet.)
This is the right place. Welcome. :)
Show 18 quoted lines
> I have the following repository tree:
> 
> C
> |\
> | B
> | /
> A
> 
> Commit A: Parents=(). Initial commit. Contains file foo with content "ABC".
> Commit B: Parents=(A). Represents a commit on some feature branch. Contains file foo with content "XYZ".
> Commit C: Parents=(A, B). Represents a merge commit of a feature branch back to the main branch. Contains file foo with content "XYZ".
> 
> I expected "git log --merges foo" to show C, however, the log is
> empty! Specifying "--full-history" results in the correct history,
> therefore I assume, I misunderstand Git's default history
> simplification algorithm. Unfortunately, the example in the Git docs
> at [1] does not contain the very same situation (although it is
> probably one of the most common situations...).

I don't think "--merges" is relevant to the simplification here. By asking for "foo", that turns on history simplification. Since the merge at C took one side directly, that means we can cull the parent link that leads to A (its foo=ABC did not contribute to the final outcome). And then C is TREESAME to its only remaining parent (they both have foo=XYZ), so it can be removed, leaving only commit B to be passed to the next stage.

And then we apply "--merges", and see that B is not a merge, and so do not show it (but we still traverse it, of course).

In theory we could apply "--merges" first (by simplifying history to shrink any chains of non-merges to a single point). But I don't think there's any way to do that currently with git.

-Peff

← back to recent threads