All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Subject: Re: Merging back from master but keeping a subtree
Date: Sat, 17 Sep 2011 23:37:19 -0400	[thread overview]
Message-ID: <20110918033719.GB17977@sigill.intra.peff.net> (raw)
In-Reply-To: <87y5xn8v6z.fsf@dod.no>

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

  reply	other threads:[~2011-09-18  3:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-17  7:49 Merging back from master but keeping a subtree Steinar Bang
2011-09-18  3:37 ` Jeff King [this message]
2011-11-16 13:39   ` Steinar Bang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110918033719.GB17977@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.