git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Coping commits from one branch to another
@ 2008-01-22 15:45 Ciprian Dorin Craciun
  2008-01-22 16:03 ` Johannes Schindelin
  2008-01-22 16:07 ` Johan Herland
  0 siblings, 2 replies; 3+ messages in thread
From: Ciprian Dorin Craciun @ 2008-01-22 15:45 UTC (permalink / raw)
  To: git

    Hello all!

    My question is how can I use git-rebase -- or a similar command --
to actually copy the commits from one branch to another.

    For example I have cloned the linux kernel repository and I have
the following branches:
    -- v2.6.22-stable
    -- v2.6.23-local
    -- v2.6.23-stable
    -- v2.6.23-local

    The difference between v2.6.x-stable and v2.6.x-local are just a
few minor patches (which are not in the default kernel tree) and some
script files added to make the compilation and deployment easier for
my setup. Thus v2.6.x-local is an ancestor of v2.6.x-stable. Now when
v2.6.24 will arrive I would like to "copy" the commits from
v2.6.23-local to v2.6.24-local.

    One solution would be to use:
    git rebase --onto v2.6.24-local v2.6.23-stable v2.6.23-local

    But this will not copy the commits, but actually move them. (And I
do not see anything about this case in the git rebase documentation,
or pointers to other commands similar to rebase.)

    So how should this be done?

    Thanks,
    Ciprian Craciun.

    P.S.: The simplest solution would be to obtain the list of commits
and apply them with cherry-pick... But this is not that straight
forward...

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Coping commits from one branch to another
  2008-01-22 15:45 Coping commits from one branch to another Ciprian Dorin Craciun
@ 2008-01-22 16:03 ` Johannes Schindelin
  2008-01-22 16:07 ` Johan Herland
  1 sibling, 0 replies; 3+ messages in thread
From: Johannes Schindelin @ 2008-01-22 16:03 UTC (permalink / raw)
  To: Ciprian Dorin Craciun; +Cc: git

Hi,

On Tue, 22 Jan 2008, Ciprian Dorin Craciun wrote:

>     Hello all!
> 
>     My question is how can I use git-rebase -- or a similar command --
> to actually copy the commits from one branch to another.
> 
>     For example I have cloned the linux kernel repository and I have
> the following branches:
>     -- v2.6.22-stable
>     -- v2.6.23-local
>     -- v2.6.23-stable
>     -- v2.6.23-local
> 
>     The difference between v2.6.x-stable and v2.6.x-local are just a
> few minor patches (which are not in the default kernel tree) and some
> script files added to make the compilation and deployment easier for
> my setup. Thus v2.6.x-local is an ancestor of v2.6.x-stable. Now when
> v2.6.24 will arrive I would like to "copy" the commits from
> v2.6.23-local to v2.6.24-local.
> 
>     One solution would be to use:
>     git rebase --onto v2.6.24-local v2.6.23-stable v2.6.23-local
> 
>     But this will not copy the commits, but actually move them. (And I
> do not see anything about this case in the git rebase documentation,
> or pointers to other commands similar to rebase.)

Very easy.  Do this before rebasing:

	git checkout -b v2.6.24-local v2.6.23-local

then proceed with

	git rebase --onto 2.6.24-stable v2.6.23-stable

Hth,
Dscho

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Coping commits from one branch to another
  2008-01-22 15:45 Coping commits from one branch to another Ciprian Dorin Craciun
  2008-01-22 16:03 ` Johannes Schindelin
@ 2008-01-22 16:07 ` Johan Herland
  1 sibling, 0 replies; 3+ messages in thread
From: Johan Herland @ 2008-01-22 16:07 UTC (permalink / raw)
  To: Ciprian Dorin Craciun; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 2099 bytes --]

On Tuesday 22 January 2008, Ciprian Dorin Craciun wrote:
>     Hello all!
> 
>     My question is how can I use git-rebase -- or a similar command --
> to actually copy the commits from one branch to another.
> 
>     For example I have cloned the linux kernel repository and I have
> the following branches:
>     -- v2.6.22-stable
>     -- v2.6.23-local
>     -- v2.6.23-stable
>     -- v2.6.23-local
> 
>     The difference between v2.6.x-stable and v2.6.x-local are just a
> few minor patches (which are not in the default kernel tree) and some
> script files added to make the compilation and deployment easier for
> my setup. Thus v2.6.x-local is an ancestor of v2.6.x-stable. Now when
> v2.6.24 will arrive I would like to "copy" the commits from
> v2.6.23-local to v2.6.24-local.
> 
>     One solution would be to use:
>     git rebase --onto v2.6.24-local v2.6.23-stable v2.6.23-local
> 
>     But this will not copy the commits, but actually move them. (And I
> do not see anything about this case in the git rebase documentation,
> or pointers to other commands similar to rebase.)
> 
>     So how should this be done?

Actually, you're pretty much on the right track, already. git-rebase does 
in fact _copy_ the commits onto the target branch. It's just that it also 
moves the ref (i.e. branch name) along, so that the old commits are no 
longer reachable. Consider the following:

	git checkout -b v2.6.24-local_new v2.6.23-local
	git rebase --onto v2.6.24-local v2.6.23-stable

This checks out a new branch (v2.6.24-local_new) that initially points at 
the same commit as v2.6.23-local. We then rebase all the commits between 
v2.6.23-stable and v2.6.24-local_new (which is the same as v2.6.23-local) 
on top of the existing v2.6.24-local branch. v2.6.24-local_new will move 
along and point to the last commit _after_ rebase, but you haven't moved 
v2.6.23-local in the process, so it still points to the corresponding last 
commit _before_ rebase.


Have fun!

...Johan


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

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-01-22 16:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-22 15:45 Coping commits from one branch to another Ciprian Dorin Craciun
2008-01-22 16:03 ` Johannes Schindelin
2008-01-22 16:07 ` Johan Herland

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).