threads / discuss / 4136

Howto get the merge-base ?

Subject: Howto get the merge-base ?

## tl;dr

5 messages between May 14, 2006 and May 14, 2006.

replies: 4people: 3as markdown or json

Bertrand Jacquin· May 14, 2006, 17:21 UTC · lore
Hi,

I'm trying to know which commit it the parent of a merge. For exemple if I do that :

   o Merge
  / \
 /   \
 |   |
 |   o Commit D
 |   |
 |   o Commit C
 |   |
 o   | Commit B
 \  /
  \/
  o Commit A
  |
  o Init
How could I know that ``Commit A'' is the merge-base of ``Merge'' ?

I try to get this git-merge-base but result is strange and quiet mysterious as he return me always second args I passed to. I'm using git 1.3.2

-- 
Beber
#e.fr@freenode
Junio C Hamano· May 14, 2006, 17:44 UTC · re: Bertrand Jacquin · lore

Re: Howto get the merge-base ?

"Bertrand Jacquin" <beber.mailing@gmail.com> writes:
Show 19 quoted lines
> I'm trying to know which commit it the parent of a merge.
> For exemple if I do that :
>
>   o Merge
>  / \
> /   \
> |   |
> |   o Commit D
> |   |
> |   o Commit C
> |   |
> o   | Commit B
> \  /
>  \/
>  o Commit A
>  |
>  o Init
>
> How could I know that ``Commit A'' is the merge-base of ``Merge'' ?
> I try to get this git-merge-base but result is strange and quiet
> mysterious as he return me always second args I passed to.

It is mysterious to me because you did not say what you gave as arguments ;-).

If I am reading you correctly, you already have a "Merge" commit, made by you or somebody else, and are trying to figure out where the merge base was. If that is the case:

	git-merge-base Merge^1 Merge^2
in other words
	git-merge-base CommitB CommitD        
is what you are looking for?

But what do you need that information for? To reproduce somebody else's merge?

Bertrand Jacquin· May 14, 2006, 18:04 UTC · re: Junio C Hamano · lore

Re: Howto get the merge-base ?

On 5/14/06, Junio C Hamano <junkio@cox.net> wrote:
Show 27 quoted lines
> "Bertrand Jacquin" <beber.mailing@gmail.com> writes:
>
> > I'm trying to know which commit it the parent of a merge.
> > For exemple if I do that :
> >
> >   o Merge
> >  / \
> > /   \
> > |   |
> > |   o Commit D
> > |   |
> > |   o Commit C
> > |   |
> > o   | Commit B
> > \  /
> >  \/
> >  o Commit A
> >  |
> >  o Init
> >
> > How could I know that ``Commit A'' is the merge-base of ``Merge'' ?
>
> > I try to get this git-merge-base but result is strange and quiet
> > mysterious as he return me always second args I passed to.
>
> It is mysterious to me because you did not say what you gave as
> arguments ;-).

I was using git-merge-base ``merge-ish'' ``comit-ish''. Docs about it is atrocious so was trying many but not the one good. Blam me.

Show 9 quoted lines
> If I am reading you correctly, you already have a "Merge"
> commit, made by you or somebody else, and are trying to figure
> out where the merge base was.  If that is the case:
>
>         git-merge-base Merge^1 Merge^2
>
> in other words
>
>         git-merge-base CommitB CommitD
That's ok :)
> is what you are looking for?
Yes ! Thanks :)
> But what do you need that information for?  To reproduce
> somebody else's merge?

No, that's just on the following of git-send-mail-commit.sh thread (or something near). To make a readable merge mail with diffstat and summury.

-- 
Beber
#e.fr@freenode
Junio C Hamano· May 14, 2006, 18:12 UTC · re: Bertrand Jacquin · lore

Re: Howto get the merge-base ?

"Bertrand Jacquin" <beber.mailing@gmail.com> writes:
Show 24 quoted lines
> On 5/14/06, Junio C Hamano <junkio@cox.net> wrote:
>> "Bertrand Jacquin" <beber.mailing@gmail.com> writes:
>>
>> > I'm trying to know which commit it the parent of a merge.
>> > For exemple if I do that :
>> >
>> >   o Merge
>> >  / \
>> > /   \
>> > |   |
>> > |   o Commit D
>> > |   |
>> > |   o Commit C
>> > |   |
>> > o   | Commit B
>> > \  /
>> >  \/
>> >  o Commit A
>> >  |
>> >  o Init
>> >
> No, that's just on the following of git-send-mail-commit.sh thread (or
> something near). To make a readable merge mail with diffstat and
> summury.

For that you do not want merge-base. If your mainline was A-B and you merged a side branch B-C-D with the merge, then to people who tracked your head (that's the audience of "merge mail", I presume) they just need to see:

	git diff --stat M^1..M
	git rev-list --no-merges --pretty M^1..M | git shortlog

The diffstat is "what damage was inflicted on the branch you have been following with this merge", so the diff between the trees before and after the merge is what you want. And the rev-list piped to shortlog is to show "what commits were _not_ present on this branch before the merge, but are present after the merge" (it could be spelled M^1..M^2 but the above would handle octopus as well).

Linus Torvalds· May 14, 2006, 18:40 UTC · re: Bertrand Jacquin · lore

Re: Howto get the merge-base ?

On Sun, 14 May 2006, Bertrand Jacquin wrote:
Show 20 quoted lines
> 
> I'm trying to know which commit it the parent of a merge.
> For exemple if I do that :
> 
>   o Merge
>  / \
> /   \
> |   |
> |   o Commit D
> |   |
> |   o Commit C
> |   |
> o   | Commit B
> \  /
>  \/
>  o Commit A
>  |
>  o Init
> 
> How could I know that ``Commit A'' is the merge-base of ``Merge'' ?
Well, Junio already answered, but I'd like to comment a bit further.
There may not be "one" merge-base. There can be several:
		Merge
		  |
		  A
		 / \
		B   C
		|\ /|
		| X |
		|/ \|
		D   E
		 \ /
		  F
		  |
Here the merge (A) has two equally good merge bases: D and E.

If you want all of these merge-bases, you need to add the "--all" flag to git-merge-base.

On the git archive, try this trivia shell pipeline:
	git-rev-list --parents HEAD |
		sed -n '/^[0-9a-f]* [0-9a-f]* [0-9a-f]*$/ p' |
		while read a b c
		do
			echo $a: $(git merge-base --all $b $c)
		done | less -S

and you'll be able to easily pick up examples of where there are real multiple merge bases. For example, commit 4da8cbc2.. has that.

If you want to examine _why_ it has multiple merge-bases, do:
	gitk 4da8cbc2 --not 5910e997 52b70d56

(where the two "not" commits are the merge bases for it) which shows that merge and the criss-crossing nature of the history leading up to it.

NOTE! Most of the time, multiple merge bases do not really matter all that much, and you'd get the same merge regardless of which one you would choose as the base. Still, they _can_ matter.

			Linus

← back to recent threads