Search code examples
gittfsmergegit-mergetfvc

Does Git allow baseless merges?


I know that baseless merges in Team Foundation Version Control are dangerous. I was wondering if it was also dangerous with Git.

If you are unfamiliar with a baseless merge, here's an example. The red dotted line is a baseless rebase/merge.

Is it safe to do this with Git?


Solution

  • Well, yes and no. Team Foundation Version Control (TFVC) enforces a branch hierarchy, and it has a rule that you can only merge from a branch to its parent or a child. In the image you provide, you can merge B to C and that is not a baseless merge. Merging B into C will use B3 as the common ancestor and produce a nice, easy to deal with three-way merge.

    However, TFVC does not allow you to merge A directly into C. You are expected to merge A into B, then merge the result into C. If you want to go around this workflow, you're stuck doing a baseless merge, which skips common ancestor computation. The result is that you're doing a three-way merge without a common ancestor - both files look like new additions and any differences between them will be treated as conflicts.

    It's a giant pain.

    Git doesn't try to enforce any branch hierarchies, so in your illustration, you can merge from C to A without penalty. A3 would be the common ancestor in this case, and you would have the following graph:

                    C  1--2--3----M
                      /          /
            B  1--2--3--4--5    /
              /                /
    A  1--2--3--4--5-----------
    

    So this scenario is not a baseless merge in Git, however you can still have a baseless merge in Git. If you try to merge two branches that have no common ancestor (no merge base) then this would be a baseless merge and it would have all the problems that occur when you do a baseless merge in TFVC.

    You can try this by creating a new branch with no parents (via git checkout --orphan).