All of lore.kernel.org
 help / color / mirror / Atom feed
From: Johan Herland <johan@herland.net>
To: David <wizzardx@gmail.com>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>
Subject: Re: User's mailing list? And multiple cherry pick
Date: Wed, 04 Jun 2008 10:16:25 +0200	[thread overview]
Message-ID: <200806041016.26066.johan@herland.net> (raw)
In-Reply-To: <18c1e6480806040013l72da09aem30f91183e4fcbe41@mail.gmail.com>

On Wednesday 04 June 2008, David wrote:
> > rebase --onto?
> 
> Thanks, I checked the manuals further, and it looks like this will
> (mostly) do what I need.
> 
> What's still missing is multiple cherry pick ;-)
> 
> In other words, is there a simple way to *copy* a large number of
> commits from one branch to another, without rebasing?

Depends on you definition of "simple". Here are 5 commands that gets the job done in a (IMHO) conceptually simple way.

Use

	git checkout -b [tmpBranch] [fromBranch]

to create (and checkout) a _new_ branch pointing to the same commit as the "from"-branch. Then use

	git rebase --onto [toBranch] [fromBranchStart] [tmpBranch]

to rebase all commits between [fromBranchStart] and [fromBranch] on top of [toBranch]. Since this was done with HEAD == [tmpBranch], the original [fromBranch] is not moved, and therefore *still* points to the old commits. [tmpBranch], however, have been moved to point at the rebased commits. This in effect *copies* the commits from [fromBranch] to [tmpBranch]. Now, all that remains is to reconcile [tmpBranch] and [toBranch], and finally remove [tmpBranch]:

	git checkout [toBranch]
	git merge [tmpBranch]
	git branch -d [tmpBranch]

The merge should be a simple fast-forward without any conflicts.

Here is an illustrated version of what's going on:

Initial layout:

	          G---H---I  <---- [fromBranch]
	         /
	A---B---C---D---E---F  <-- [toBranch]
	        ^----------------- [fromBranchStart]

git checkout -b [tmpBranch] [fromBranch]

	          G---H---I  <---- [fromBranch]
	         /        ^------- [tmpBranch]      
	A---B---C---D---E---F  <-- [toBranch]
	        ^----------------- [fromBranchStart]

git rebase --onto [toBranch] [fromBranchStart] [tmpBranch]

	          G---H---I  <------------------- [fromBranch]
	         /              
	A---B---C---D---E---F---G'---H'---I'  <-- [tmpBranch]
	        ^           ^-------------------- [toBranch]
	        --------------------------------- [fromBranchStart]

git checkout [toBranch]
git merge [tmpBranch]
git branch -d [tmpBranch]

	          G---H---I  <------------------- [fromBranch]
	         /              
	A---B---C---D---E---F---G'---H'---I'  <-- [toBranch]
	        ^-------------------------------- [fromBranchStart]


This should also work even if your commit graphs are considerably more complicated.

If you need to drop/edit/squash any commits between [fromBranchStart] and [fromBranch], simply add a "--interactive" to the rebase command.


Have fun!

...Johan

-- 
Johan Herland, <johan@herland.net>
www.herland.net

  parent reply	other threads:[~2008-06-04  8:18 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-04  6:55 User's mailing list? And multiple cherry pick David
2008-06-04  6:58 ` Junio C Hamano
2008-06-04  7:13   ` David
2008-06-04  8:05     ` Jakub Narebski
2008-06-04  8:23       ` Johan Herland
2008-06-04  8:30       ` David
2008-06-04  9:39         ` Wincent Colaiuta
2008-06-04 10:02           ` David
2008-06-04 11:02             ` Wincent Colaiuta
2008-06-04 11:09             ` Jakub Narebski
2008-06-04 18:09             ` Björn Steinbrink
2008-06-04  8:16     ` Johan Herland [this message]
2008-06-04  7:39 ` Jakub Narebski
2008-06-04  8:11   ` David
2008-06-04  8:50     ` Jakub Narebski
2008-06-04  9:37       ` David
2008-06-04  9:47         ` Jakub Narebski
2008-06-04 11:36     ` Theodore Tso
2008-06-04 10:38   ` Karl Hasselström
2008-06-04 11:10     ` Miklos Vajna
2008-06-04  8:00 ` Stephan Beyer
2008-06-04  8:20   ` David

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=200806041016.26066.johan@herland.net \
    --to=johan@herland.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=wizzardx@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.