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

Re: [DRAFT] Branching and merging with git

From
Junio C Hamano <junkio@cox.net>
Date
Nov 22, 2006, 11:51 UTC
Message-ID
<7vy7q3snq8.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<7vslghftix.fsf@assigned-by-dhcp.cox.net>
Junio C Hamano <junkio@cox.net> writes:
Show 6 quoted lines
> If you want an esoteric topic for an introductory documentation,
> it would be more useful to talk about evil merges (an evil merge
> is a merge commit whose result does not match any of its
> parents).  A good example is found in
>
> 	git show v1.0.0
I actually remembered a better one.
        Subject: Necessity of "evil" merge and topic branches
        Date: Wed, 17 May 2006 23:25:55 -0700
        Message-ID: <7vy7wz6e8c.fsf@assigned-by-dhcp.cox.net>

This talks about a real-world evil merge and the reason why it was necessary, and speculates a possible way to make life easier. I actually later used the "third branch to remember the evil merge between two topics" technique I talked about in the message to merge in another pair of topics, and it turned out that it worked rather well.

There were two logically independent topics:
 - lt/setup.  Two commits, changing the calling convention of
   setup_git_directory() function -- the final tip of the topic
   was at a633fca0.
 - js/mv.  Three commits, making git-mv a built-in after
   refactoring some code from other parts of the system -- the
   final tip of the topic was at ac64a722).

They were not "obviously correct" when they started, so a topic branch was used for each. They had textually and semantically some conflicts, and if they were to progress at different paces, there was a need for an evil merge when the later one is merged to master.

So I created another branch to merge the two topics together and resolved their conflicts while my reading of their code were still fresh.

	git checkout -b __/setup-n-mv js/mv
        git pull . lt/setup
	git checkout next
        git pull . __/setup-n-mv

Later js/mv became ready to be merged first. So I merged it to 'master'.

	git checkout master
        git pull . js/mv

I was planning to cook lt/setup a bit longer but eventually decided to merge it to 'master' as well after a short while.

	git checkout master
        git pull . __/setup-n-mv

I could have pulled lt/setup into master but then I would have had to resolve the conflict between the two branches. Since I recorded the resolution earlier by making the merge, and pulled that branch (which contained all of lt/setup already) into 'master', I did not have to remember what I need to adjust when I did so. If lt/setup had further updates on its own after the "third branch __/setup-n-mv" was made, I would have then pulled the tip of lt/setup into 'master' to complete the merge, and that would have also resulted in non-conflicting simple merge.

This would have worked equally well if lt/setup were to graduate first.

This might look too complex at the first look, but I thought it might be an interesting topic in the "hints for managing your topic branches" section.

Previous: J. Bruce Fields
Message 11 of 11 in “Re: [DRAFT] Branching and merging with git”
  1. Junio C HamanoNov 18, 2006
  2. [DRAFT 2] Branching and merging with gitlinux@horizon.com, Nov 20, 2006
  3. 1/2 Branching and merging with gitJunio C Hamano, Nov 22, 2006
  4. 2/2 Branching and merging with gitJunio C Hamano, Nov 22, 2006
  5. Rene ScharfeNov 22, 2006
  6. J. Bruce FieldsDec 4, 2006
  7. J. Bruce FieldsDec 4, 2006
  8. Johannes SchindelinDec 4, 2006
  9. Jakub NarebskiDec 15, 2006
  10. J. Bruce FieldsDec 15, 2006
  11. Junio C HamanoNov 22, 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.