From: Andreas Ericsson <ae@op5.se>
To: Anton Altaparmakov <aia21@cam.ac.uk>
Cc: git@vger.kernel.org
Subject: Re: Best way to generate a git tree containing only a subset of commits from another tree?
Date: Thu, 23 Mar 2006 01:44:15 +0100 [thread overview]
Message-ID: <4421EF5F.3000601@op5.se> (raw)
In-Reply-To: <Pine.LNX.4.64.0603221920260.22475@hermes-2.csi.cam.ac.uk>
Anton Altaparmakov wrote:
> As subject, what is at present the best way to generate a git tree
> containing only a subset of commits from another tree.
>
git format-patch -k <start-commit>..<end-commit> --stdout | git am -k
Make sure you're on the right branch first, but see below.
> So I have /usr/src/my-big-tree and /usr/src/linux-2.6 and now I want to
> add some of the commits in my-big-tree to the tree linux-2.6 so I can push
> out to Linus.
>
I sense some nomenclature confusion here. By "tree", do you happen to
mean "branch", or possibly "repository"? I know bk does things with
trees that's vaguely git-ish, but a tree in git is, basically, just a
simplified directory listing (without depth, although it can contain
other trees ad infinitum iiuc).
If you mean "branch" (or repository, it doesn't matter since by then
you'll have something like a master branch anyway), as I think you do,
then let's assume the Vanilla Linux lives in the "linus" branch.
You would then do
$ git checkout -b for-linus linus
followed by either multiple
$ git cherry-pick <commit-ish>
or, if the commits are all in series, an iteration of the following
$ git format-patch --stdout <start-commit>..<end-commit> | git am -k
If you have several topic branches, one for each series of commits, you
should be able to do an octopus, like so:
$ git pull . <topic-branches-to-publish>
If you *don't* have several topic branches, or if some commits aren't in
topic-branches, you could try something like this (untested, although it
shouldn't break anything except the for-linus branch which you can
re-create fairly simply)
$ for b in <topic-branches-for-linus>; do
git checkout $b
git rebase for-linus || (git reset --hard; echo $b >> to-merge)
done
# now merge what couldn't be rebased
$ git checkout for-linus
$ git pull . $(cat to-merge)
In your "please-pull" mail to Linus, ask him to pull the 'for-linus'
branch. When he's done so, pull his 'master' branch to your 'linus',
branch and remove the 'for-linus' branch and re-create it from Linus'
master branch again. If your vanilla tree is up-to-date and he pulls
from you before pulling from someone else or adding other commits this
isn't necessary, although you'll have to do
$ git checkout linus; git pull . for-linus
to get the vanilla branch up to speed with Linus' HEAD.
That turned out a bit longer than I expected, and with me being slightly
off sobriety at the moment it would be good if someone less so could
double-check the thinking. Incidentally, this is one of the reasons why
topic-branches is such a Good Thing (tm).
> Preferable I would like to do it so that later when Linus has pulled from
> my /usr/src/linux-2.6 tree, I do a "git pull" of Linus' tree from
> /usr/src/my-big-tree and it all works correctly and I don't end up with
> the same commits twice.
>
> Is that possible at all?
>
I hope so, or I just spent a good 20 minutes not drinking beer for
nothing. ;)
> If not what can I do to do it cleanly? Does git help in any way or do I
> literally have to export all my commits from /usr/src/my-big-tree to diff
> style patches and then throw away the tree, clone Linus tree after he has
> pulled my /usr/src/linux-2.6 tree and commit all my generated diff patches
> again? That would be rather horrible to have to do...
>
It's worth re-iterating:
git format-patch --stdout -k <start-commit>..<end-commit> > patch-series
git am -k patch-series
It will save you a lot of work.
> I am happy to be pointed to a FAQ or RTFM if you tell me where to look for
> it...
>
Hopefully I just supplied one that can be re-used with some
text-mangling by someone capable of being legible and making sense at
the same time.
For more info, check out the man-pages of the commands above (notably
the cherry-pick man-page and the pull command's "merge with local" feature).
--
Andreas Ericsson andreas.ericsson@op5.se
OP5 AB www.op5.se
Tel: +46 8-230225 Fax: +46 8-230231
next prev parent reply other threads:[~2006-03-23 0:44 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-03-22 19:28 Best way to generate a git tree containing only a subset of commits from another tree? Anton Altaparmakov
2006-03-22 21:28 ` Radoslaw Szkodzinski
2006-03-23 0:25 ` Petr Baudis
2006-03-23 0:44 ` Andreas Ericsson [this message]
2006-03-23 1:38 ` Junio C Hamano
2006-03-23 3:20 ` Andreas Ericsson
2006-03-23 3:43 ` Linus Torvalds
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=4421EF5F.3000601@op5.se \
--to=ae@op5.se \
--cc=aia21@cam.ac.uk \
--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.