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

Re: Howto get the merge-base ?

From
Linus Torvalds <torvalds@osdl.org>
Date
May 14, 2006, 18:40 UTC
Message-ID
<Pine.LNX.4.64.0605141122380.3866@g5.osdl.org>
In-Reply-To
<4fb292fa0605141021r20cefaa0he592b9c713ede333@mail.gmail.com>
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
Previous: Junio C Hamano
Message 5 of 5 in “Howto get the merge-base ?”
  1. Bertrand JacquinMay 14, 2006
  2. Junio C HamanoMay 14, 2006
  3. Bertrand JacquinMay 14, 2006
  4. Junio C HamanoMay 14, 2006
  5. Linus TorvaldsMay 14, 2006

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.