{"thread":{"id":"11705","subject":"Coping commits from one branch to another","startedAt":"2008-01-22T15:45:18Z","lastAt":"2008-01-22T16:07:59Z","messageCount":3,"participants":["Ciprian Dorin Craciun","Johannes Schindelin","Johan Herland"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"66314","messageId":"8e04b5820801220745m3736686exf631f31c9e6d785a@mail.gmail.com","threadId":"11705","inReplyTo":null,"subject":"Coping commits from one branch to another","fromName":"Ciprian Dorin Craciun","fromEmail":"ciprian.craciun@gmail.com","sentAt":"2008-01-22T15:45:18Z","receivedAt":"2008-01-22T15:45:18Z","isPatch":false,"sender":{"key":"ciprian.craciun@gmail.com","avatar":"https://gravatar.com/avatar/9685eb13288a2c28bdde10acdcda9f15d495efad7b12bf49e3525eb7b8acf944?d=mp&s=160"},"body":"    Hello all!\n\n    My question is how can I use git-rebase -- or a similar command --\nto actually copy the commits from one branch to another.\n\n    For example I have cloned the linux kernel repository and I have\nthe following branches:\n    -- v2.6.22-stable\n    -- v2.6.23-local\n    -- v2.6.23-stable\n    -- v2.6.23-local\n\n    The difference between v2.6.x-stable and v2.6.x-local are just a\nfew minor patches (which are not in the default kernel tree) and some\nscript files added to make the compilation and deployment easier for\nmy setup. Thus v2.6.x-local is an ancestor of v2.6.x-stable. Now when\nv2.6.24 will arrive I would like to \"copy\" the commits from\nv2.6.23-local to v2.6.24-local.\n\n    One solution would be to use:\n    git rebase --onto v2.6.24-local v2.6.23-stable v2.6.23-local\n\n    But this will not copy the commits, but actually move them. (And I\ndo not see anything about this case in the git rebase documentation,\nor pointers to other commands similar to rebase.)\n\n    So how should this be done?\n\n    Thanks,\n    Ciprian Craciun.\n\n    P.S.: The simplest solution would be to obtain the list of commits\nand apply them with cherry-pick... But this is not that straight\nforward...\n"},{"id":"66317","messageId":"alpine.LSU.1.00.0801221601570.5731@racer.site","threadId":"11705","inReplyTo":"8e04b5820801220745m3736686exf631f31c9e6d785a@mail.gmail.com","subject":"Re: Coping commits from one branch to another","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-01-22T16:03:13Z","receivedAt":"2008-01-22T16:03:13Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 22 Jan 2008, Ciprian Dorin Craciun wrote:\n\n>     Hello all!\n> \n>     My question is how can I use git-rebase -- or a similar command --\n> to actually copy the commits from one branch to another.\n> \n>     For example I have cloned the linux kernel repository and I have\n> the following branches:\n>     -- v2.6.22-stable\n>     -- v2.6.23-local\n>     -- v2.6.23-stable\n>     -- v2.6.23-local\n> \n>     The difference between v2.6.x-stable and v2.6.x-local are just a\n> few minor patches (which are not in the default kernel tree) and some\n> script files added to make the compilation and deployment easier for\n> my setup. Thus v2.6.x-local is an ancestor of v2.6.x-stable. Now when\n> v2.6.24 will arrive I would like to \"copy\" the commits from\n> v2.6.23-local to v2.6.24-local.\n> \n>     One solution would be to use:\n>     git rebase --onto v2.6.24-local v2.6.23-stable v2.6.23-local\n> \n>     But this will not copy the commits, but actually move them. (And I\n> do not see anything about this case in the git rebase documentation,\n> or pointers to other commands similar to rebase.)\n\nVery easy.  Do this before rebasing:\n\n\tgit checkout -b v2.6.24-local v2.6.23-local\n\nthen proceed with\n\n\tgit rebase --onto 2.6.24-stable v2.6.23-stable\n\nHth,\nDscho\n"},{"id":"66318","messageId":"200801221708.03399.johan@herland.net","threadId":"11705","inReplyTo":"8e04b5820801220745m3736686exf631f31c9e6d785a@mail.gmail.com","subject":"Re: Coping commits from one branch to another","fromName":"Johan Herland","fromEmail":"johan@herland.net","sentAt":"2008-01-22T16:07:59Z","receivedAt":"2008-01-22T16:07:59Z","isPatch":false,"sender":{"key":"johan@herland.net","avatar":"https://avatars.githubusercontent.com/u/547031?v=4"},"body":"On Tuesday 22 January 2008, Ciprian Dorin Craciun wrote:\n>     Hello all!\n> \n>     My question is how can I use git-rebase -- or a similar command --\n> to actually copy the commits from one branch to another.\n> \n>     For example I have cloned the linux kernel repository and I have\n> the following branches:\n>     -- v2.6.22-stable\n>     -- v2.6.23-local\n>     -- v2.6.23-stable\n>     -- v2.6.23-local\n> \n>     The difference between v2.6.x-stable and v2.6.x-local are just a\n> few minor patches (which are not in the default kernel tree) and some\n> script files added to make the compilation and deployment easier for\n> my setup. Thus v2.6.x-local is an ancestor of v2.6.x-stable. Now when\n> v2.6.24 will arrive I would like to \"copy\" the commits from\n> v2.6.23-local to v2.6.24-local.\n> \n>     One solution would be to use:\n>     git rebase --onto v2.6.24-local v2.6.23-stable v2.6.23-local\n> \n>     But this will not copy the commits, but actually move them. (And I\n> do not see anything about this case in the git rebase documentation,\n> or pointers to other commands similar to rebase.)\n> \n>     So how should this be done?\n\nActually, you're pretty much on the right track, already. git-rebase does \nin fact _copy_ the commits onto the target branch. It's just that it also \nmoves the ref (i.e. branch name) along, so that the old commits are no \nlonger reachable. Consider the following:\n\n\tgit checkout -b v2.6.24-local_new v2.6.23-local\n\tgit rebase --onto v2.6.24-local v2.6.23-stable\n\nThis checks out a new branch (v2.6.24-local_new) that initially points at \nthe same commit as v2.6.23-local. We then rebase all the commits between \nv2.6.23-stable and v2.6.24-local_new (which is the same as v2.6.23-local) \non top of the existing v2.6.24-local branch. v2.6.24-local_new will move \nalong and point to the last commit _after_ rebase, but you haven't moved \nv2.6.23-local in the process, so it still points to the corresponding last \ncommit _before_ rebase.\n\n\nHave fun!\n\n...Johan\n\n\n-- \nJohan Herland, <johan@herland.net>\nwww.herland.net\n"}]}