Re: Merging back from master but keeping a subtree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Sep 17, 2011 at 09:49:40AM +0200, Steinar Bang wrote:

> I have a long lived branch that changes a directory and its
> subdirectory, ie. 
>  top/middle/mydirectory
> 
> Now I want to merge in an updated remoterepo/master and keep everything
> from that master, except for mydirectory and its subdirectory, where I
> would like to keep everything from my branch.

Git should generally do that automatically, unless both sides are
changing mydirectory. In which case it will produce conflicts.

Are you sure you really want to just throw out what the other side did
in mydirectory?

> I tried a regular merge, and used
>  git checkout --ours
>  git add
> and 
>  git checkout --theirs
>  git add
> as appropriate on all conflicts.
> 
> But the result didn't build, and the build errors don't make much sense,
> so I think they are caused by "successful" merges giving bad results.

If git was able to auto-merge some files, then they will not be marked
as conflicts in the index. And "git checkout --ours" is about looking in
the index for conflicted entries, and then selecting one side.

I think what you want instead is to do is (assuming you really want to
throw out their side):

  1. Start a merge between them and us:

       git merge --no-commit remoterepo/master

  2. Throw out whatever the merge came up with and make it look like
     their tree:

       git checkout remoterepo/master -- top

  3. Now overwrite their version of mydirectory with what was in your
     branch:

       git checkout HEAD -- top/middle/mydirectory

  4. Commit the resulting tree:

       git commit

-Peff
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]