3

I'm learning Git, and am finding the tutorial on this site very useful. On that page, concerning merging, it includes:

         +---------- (D) ---------------+
        /             |                  \
(A) -- (B) -- (C) -------------- (E) -- (F)
                      |                  |
                 fix-headers           master
                                         |
                                        HEAD

The merge commit is (F), having parents (D) and (E). Because (B) is the common ancestor between (D) and (E), the files in (F) should contain the changes between (B) and (D), namely the heading fixes, incorporated into the files from (E).

I don't understand why you would worry about the common ancestor B. Why can't you just merge D and E to produce F? D will have been derived from B but might contain differences you want. There might have been a number of commits between B and D, with changes being made and taken out.

Martin Geisler
  • 72,968
  • 25
  • 171
  • 229
  • git uses changesets just like mercurial, so a Node only contains the difference to its parent. – sleeplessnerd Apr 01 '11 at 12:11
  • 2
    @sleeplessnerd Actually, Git stores complete files, not diffs. Unless you meant something else by that? – Jonathan Apr 01 '11 at 12:16
  • 1
    See [this question](http://stackoverflow.com/q/4129049/11343) for the advantages of 3-way merge – CharlesB Apr 01 '11 at 12:28
  • You're wrong sleeplessnerd. Each commit in git points to a complete snapshot of the entire project. If a certain file is different, a separate snapshot of the new version is stored rather than just the diffs. Mercurial OTOH uses delta storage. – Noufal Ibrahim Apr 01 '11 at 12:34

3 Answers3

4

(I hesitate to ask if this is an April Fool's, I don't want to insult anyone...)

Maybe you're not understanding that this is git doing the merge for you?

Question: Here are D and E, can you tell me what F should look like?

D                                        E
using System;                            using System;
public void main()                       public void main()
{                                        {
     Console.WriteLine("hello world");        Console.WriteLine("Hello world!");
}                                        }

Answer: No, you can't

However, if you know that B looked like this:

B
using System;
public void main()
{
     Console.WriteLine("hello world");
}

It becomes a no brainer, and git can handle this on its own.

Dunno if that answers your question...

Benjol
  • 63,995
  • 54
  • 186
  • 268
2

This is simply because merging works better if you know the common ancestor. See this answer, it has good explanation why.

Community
  • 1
  • 1
CharlesB
  • 86,532
  • 28
  • 194
  • 218
1

Wikipedia has a good introduction on 3-way merge

CharlesB
  • 86,532
  • 28
  • 194
  • 218
sehe
  • 374,641
  • 47
  • 450
  • 633