All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: skillzero@gmail.com
Cc: git@vger.kernel.org
Subject: Re: How to merge from newer branch to older branches?
Date: Tue, 21 Apr 2009 15:36:15 -0400	[thread overview]
Message-ID: <20090421193615.GB7832@coredump.intra.peff.net> (raw)
In-Reply-To: <2729632a0904211224x6e2621caxf6c169d90b760530@mail.gmail.com>

On Tue, Apr 21, 2009 at 12:24:26PM -0700, skillzero@gmail.com wrote:

> We have a "future" branch for new development. I wanted to add a new
> feature so I branched from "future" to create a branch named
> "feature". I completed the work, but now they've decided they need
> that on two older branches. It looks like this:
> [...]
> I've read I should have started from the oldest common denominator
> branch that I might ever want, but at the time I created the branch,

Right. Junio branches all topics in git from "master", but then merges
promising ones into "next". When the topic is ready for master, he can
then just merge the topic branch, pulling in that topic but not the rest
of next.

> "future" was it because we thought 1.1 and 1.2 were locked down and
> not going to add new features. But things change and I need to roll my
> feature into 1.1 and 1.2.

Yep. Advanced planning is not always possible. :)

> What's the best way to merge changes on the "feature" branch into the
> 1.1 and 1.2 branches? If I try to checkout 1.1 then 'git merge

If it is just one or two commits, you probably just want to "git
cherry-pick" them onto your older branches.

If it is a larger series, or one which might see more development, you
might want to use "git rebase" to rewrite the branch as if it were based
on 1.1, and then merge that into 1.1, 1.2, and feature.

> feature', it (obviously) merges in a bunch of changes from "future"
> that I don't want (and has a bunch of conflicts). I also tried just
> cherry-picking commits a, b, and c from the "feature" branch. That
> mostly worked, but there were some surprising conflicts. Text that had
> been inserted into a couple files (which had been untouched in 1.1 and
> 1.2) caused a conflict when it seemed like it should have just added
> the lines without conflict. I realize it's difficult to know why it
> conflicted without seeing the changes, but I'm just asking in a more
> general way how I should be doing merges like this.

Yes, without seeing the conflicts it's hard to say. But presumably the
added lines provide context, so git was having a hard time trying to
figure out where in the old file your changes would go (you can think of
cherry-pick as the moral equivalent of "git show $COMMIT | git apply";
so you are basically applying a patch on top of something that it is
not quite the same).

If you are having trouble resolving conflicts, you might try using "git
mergetool" to fire up an external resolver that may provide a richer
interface (I use xxdiff with mergetool, myself).

> Is cherry-picking the best way? It seems pretty tedious because I have
> to do each commit in reverse order (although I could script it). I was
> hoping there was a way to say "apply all the changes from when
> "feature" branched up to its tip". I would also like to preserve the
> commit history rather than just making making one big commit of all
> the changes.

In its simplest form, rebase is basically cherry-picking a series of
commits. So that would make things a bit less tedious for you, but you
will probably still end up with the same set of conflicts.

-Peff

  reply	other threads:[~2009-04-21 19:37 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-21 19:24 How to merge from newer branch to older branches? skillzero
2009-04-21 19:36 ` Jeff King [this message]
2009-04-22  5:13   ` Junio C Hamano
2009-04-22 13:34     ` Jeff King
2009-04-22 17:44     ` skillzero
2009-04-22 20:15       ` Jeff King
2009-04-22 21:01         ` skillzero
2009-04-22 21:17           ` Jeff King
2009-04-22  4:46 ` John M. Dlugosz

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=20090421193615.GB7832@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=skillzero@gmail.com \
    /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.