git: merging a subtree from one branch to another

Viewed 2986

I'm having trouble merging a subtree of a development branch back into the integration branch.

I have two branches, one was used for development and one is used for integration. Extensive development has been done in the development branch and I want to merge a portion of it back in. The specific portion that I want to merge is all contained in one subtree of the development branch.

My directory structure is like this:

[Branch A]              [Branch B]
    |                       |
    +--Dir1                 +--Dir1
    +--Dir2                 +--Dir2
        |                   |   |
        +--DirA             |   +--DirA
            |               |       |
            +--File1        |       +--File1
            +--File2        |       +--File2
                            |       +--File3
                            |       +--File4
                            +--Dir3

I want to merge Branch B/Dir2/DirA into Branch A/Dir2/DirA. I want File1 and File2 to be merged and File3 and File4 should be created in Branch A. I don't want to pick up Dir3, or any changes in Dir1.

I've tried the steps outlined by kernel.org for merging subtrees, but they fail when I do the git read-tree with:

error: Entry 'Dir1/DirA/File1' overlaps with 'Dir1/DirA/File1'.  Cannot bind.

I've tried using the subtree script which is hosted on github, but I am not having much luck with it. When I do:

git checkout Branch_A
git subtree merge -P Dir2/DirA Branch_B

I see evidence that Dir3 has been merged and the merge fails with conflicts.

I could cherry-pick the files to merge, but that seems unnecessarily convoluted for what should be a common and straight-forward problem.

4 Answers
Related