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

Re: who's on first? - following first parent and merge-management

From
Johannes Sixt <j.sixt@viscovery.net>
Date
Mar 9, 2012, 12:29 UTC
Message-ID
<4F59F7A2.3030606@viscovery.net>
In-Reply-To
<4F59F212.6030701@ira.uka.de>
Am 3/9/2012 13:05, schrieb Holger Hellmuth:
Show 17 quoted lines
> On 08.03.2012 18:30, Junio C Hamano wrote:
>> Johannes Sixt<j.sixt@viscovery.net>  writes:
>>> To avoid the situation,...
>>> This would not be necessary if the order of the merge parents could be
>>> specified, e.g.:
>>>
>>>     # on topic
>>>     git merge --into master
>>
>> I think the underlying mechanism needed to implement the above
>> shares a lot with what Jeff called "crazy idea", but where you would
>> want to be after such a merge may be different in these two cases.
> 
> I don't think there is much question that you should still be in the same
> branch. Not because you necessarily want to be in that branch. But because
> it would be surprising if git-merge changed your branch sometimes and most
> times not.

I don't think that it is so clear-cut. And for this reason, I would even go as far as to suggest that you should end up with a detached HEAD.

Before the merge we have this situation:
--o--o--o--o      <- master
   \
    o--o--o--X    <- topic

The result of 'git merge --into master' must advance branch master by the merge commit (I think there is no doubt about this):

--o--o--o--o---M  <- master
   \          /
    o--o--o--X    <- topic

Also, the index and worktree must match M (no doubt, either, IMO). But what does HEAD refer to? I see three possibilities:

1. master; as you say, this may be surprising if we were on topic before
the branch.
2. topic; but then the index would be dirty because it does not match X.
3. M, i.e. a detached HEAD; this is just a compromise and a fat warning at
the end of the merge output would be necessary that instructs the user to
checkout a suitable branch.

Now that I have tossed around these ideas, there's another caveat: What if the merge fails due to a conflict? After the conflicts were resolved, 'git commit' is needed to complete the merge. But this would create the commit where HEAD points to. IOW, we have to chose option 1 so that the merge commit advances master.

Would this be less surprising if the option were named --checkout-into?
-- Hannes
Previous: Holger HellmuthNext: Holger Hellmuth
Message 9 of 13 in “who's on first? - following first parent and merge-management”
  1. Neal KreitzingerMar 7, 2012
  2. Junio C HamanoMar 7, 2012
  3. Junio C HamanoMar 8, 2012
  4. Jeff KingMar 8, 2012
  5. Junio C HamanoMar 8, 2012
  6. Johannes SixtMar 8, 2012
  7. Junio C HamanoMar 8, 2012
  8. Holger HellmuthMar 9, 2012
  9. Johannes SixtMar 9, 2012
  10. Holger HellmuthMar 9, 2012
  11. Junio C HamanoMar 9, 2012
  12. Jonathan NiederMar 8, 2012
  13. Junio C HamanoMar 8, 2012

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.