{"thread":{"id":"35176","subject":"Moving commits from one branch to another (improving my git fu!)","startedAt":"2013-10-22T05:38:41Z","lastAt":"2013-10-22T12:51:59Z","messageCount":7,"participants":["Mandeep Sandhu","Bryan Turner","Peter Krefting","Noufal Ibrahim"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"229270","messageId":"CAC+QLdSjTjftgUBy-1cHbATZnX-UO3PavUaLwErhCaxBa-hPmQ@mail.gmail.com","threadId":"35176","inReplyTo":null,"subject":"Moving commits from one branch to another (improving my git fu!)","fromName":"Mandeep Sandhu","fromEmail":"mandeepsandhu.chd@gmail.com","sentAt":"2013-10-22T05:38:41Z","receivedAt":"2013-10-22T05:38:41Z","isPatch":false,"sender":{"key":"mandeepsandhu.chd@gmail.com","avatar":"https://gravatar.com/avatar/d85c7ffba588dd2ceaf57a974df7695a2fa7a10f3e6f5635549c9eb1b599a0db?d=mp&s=160"},"body":"Hi All,\n\nI'm in a bit of a pickle! :) So I've come to ask for help from the guru's here.\n\nMy story is not unique but somehow the various suggested solutions\ndon't seem to work in my case.\n\n* I was working on a feature which was supposed to be done off our\n'dev' branch. But instead I forgot and branched out my topic branch\nfrom master (or as we call it 'stable').\n* I did 2 commits and finished off my work. Only later realizing that\nit had to be done off 'dev'.\n* Now I want to move my 2 commits (which are the top 2 commits on my\ntopic branch) to a new branch which is branched off 'dev'.\n\n$ git branch\n* topicA\n* stable\n* dev\n\ntopicA was based on stable. But now I want to base it dev.\n\nSo I did what was most suggested, i.e use 'git rebase --onto'.\n\nHere's what I did when I was in topicA:\n\n$ git rebase dev stable topicA\n(this was suggested in the manpage as well).\n\nThis started off a massive rebase operation, because the 'dev' branch\nis vastly diverged from stable, and a lot of conflicts started\nappearing.\n\nI'm not sure if I'm doing it right here, so can anyone suggest whether\nthis is right or do I need to do it differently?\n\nPS: Please CC me (mandeepsandhu.chd@gmail.com) in your reply as I'm\nnot currently subscribed to the list.\n\nThanks for your time.\n\nRegards,\n-mandeep\n"},{"id":"229273","messageId":"alpine.DEB.2.00.1310220647400.13299@ds9.cixit.se","threadId":"35176","inReplyTo":"CAC+QLdSjTjftgUBy-1cHbATZnX-UO3PavUaLwErhCaxBa-hPmQ@mail.gmail.com","subject":"Re: Moving commits from one branch to another (improving my git fu!)","fromName":"Peter Krefting","fromEmail":"peter@softwolves.pp.se","sentAt":"2013-10-22T05:52:50Z","receivedAt":"2013-10-22T05:52:50Z","isPatch":false,"sender":{"key":"peter@softwolves.pp.se","avatar":"https://avatars.githubusercontent.com/u/990764?v=4"},"body":"Mandeep Sandhu:\n\n> Here's what I did when I was in topicA:\n>\n> $ git rebase dev stable topicA\n> (this was suggested in the manpage as well).\n\nI guess you also had an \"--onto\" in there, as the above would throw a \nsyntax error. As long as the branches are in order, I cannot see how \nthat wouldn't do what you wanted.\n\nHowever, the easiest way to do it would probably just to run:\n\n  git checkout topicA\n  git rebase dev\n\nAs long as \"dev\" already contains all the commits in \"stable\", that \nshould work fine. If not, then you would need something more \ncomplicated.\n\nAnother way to do it would be to use cherry-pick on a new branch:\n\n  git checkout -b new_topicA dev\n  git cherry-pick stable..topicA\n\n-- \n\\\\// Peter - http://www.softwolves.pp.se/\n"},{"id":"229272","messageId":"CAGyf7-EDtNPhAGm21YmPSZfWmdjhKejhmoWNG3Au5LaorOodCw@mail.gmail.com","threadId":"35176","inReplyTo":"CAC+QLdSjTjftgUBy-1cHbATZnX-UO3PavUaLwErhCaxBa-hPmQ@mail.gmail.com","subject":"Re: Moving commits from one branch to another (improving my git fu!)","fromName":"Bryan Turner","fromEmail":"bturner@atlassian.com","sentAt":"2013-10-22T06:00:30Z","receivedAt":"2013-10-22T06:00:30Z","isPatch":false,"sender":{"key":"bturner@atlassian.com","avatar":"https://gravatar.com/avatar/16bcf3167981c1ef7c804e502642366d888a35b0d0b0a4ca01fdc442aa1acb1e?d=mp&s=160"},"body":"A quick glance at your command line and the man page for git rebase\nsuggests the problem was you didn't actually use --onto. I believe the\ncorrect command would be:\n\ngit rebase --onto dev stable topicA\n\n\nThat should start by determining which commits are one topicA but not\nstable and then checkout dev and apply those new commits.\n\n\nHope this helps,\nBryan Turner\n\nOn 22 October 2013 16:38, Mandeep Sandhu <mandeepsandhu.chd@gmail.com> wrote:\n> Hi All,\n>\n> I'm in a bit of a pickle! :) So I've come to ask for help from the guru's here.\n>\n> My story is not unique but somehow the various suggested solutions\n> don't seem to work in my case.\n>\n> * I was working on a feature which was supposed to be done off our\n> 'dev' branch. But instead I forgot and branched out my topic branch\n> from master (or as we call it 'stable').\n> * I did 2 commits and finished off my work. Only later realizing that\n> it had to be done off 'dev'.\n> * Now I want to move my 2 commits (which are the top 2 commits on my\n> topic branch) to a new branch which is branched off 'dev'.\n>\n> $ git branch\n> * topicA\n> * stable\n> * dev\n>\n> topicA was based on stable. But now I want to base it dev.\n>\n> So I did what was most suggested, i.e use 'git rebase --onto'.\n>\n> Here's what I did when I was in topicA:\n>\n> $ git rebase dev stable topicA\n> (this was suggested in the manpage as well).\n>\n> This started off a massive rebase operation, because the 'dev' branch\n> is vastly diverged from stable, and a lot of conflicts started\n> appearing.\n>\n> I'm not sure if I'm doing it right here, so can anyone suggest whether\n> this is right or do I need to do it differently?\n>\n> PS: Please CC me (mandeepsandhu.chd@gmail.com) in your reply as I'm\n> not currently subscribed to the list.\n>\n> Thanks for your time.\n>\n> Regards,\n> -mandeep\n> --\n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n"},{"id":"229274","messageId":"CAC+QLdQADFPvuZ6VcDqSUYSd_sn54LK=YLqaW3U2DC1MbnsM+g@mail.gmail.com","threadId":"35176","inReplyTo":"alpine.DEB.2.00.1310220647400.13299@ds9.cixit.se","subject":"Re: Moving commits from one branch to another (improving my git fu!)","fromName":"Mandeep Sandhu","fromEmail":"mandeepsandhu.chd@gmail.com","sentAt":"2013-10-22T06:11:38Z","receivedAt":"2013-10-22T06:11:38Z","isPatch":false,"sender":{"key":"mandeepsandhu.chd@gmail.com","avatar":"https://gravatar.com/avatar/d85c7ffba588dd2ceaf57a974df7695a2fa7a10f3e6f5635549c9eb1b599a0db?d=mp&s=160"},"body":">> $ git rebase dev stable topicA\n>> (this was suggested in the manpage as well).\n>\n>\n> I guess you also had an \"--onto\" in there, as the above would throw a syntax\n> error. As long as the branches are in order, I cannot see how that wouldn't\n> do what you wanted.\n\nYes, you're right. There was \"--onto\" there.\n\nThe only problem is that there were a LOT of conflicts when I ran this\ncmd in places which have nothing to do with my commit. And as I said,\ndev is vastly different from stable.\n\n>\n> However, the easiest way to do it would probably just to run:\n>\n>  git checkout topicA\n>  git rebase dev\n>\n> As long as \"dev\" already contains all the commits in \"stable\", that should\n> work fine. If not, then you would need something more complicated.\n\nI don't think thats the case currently. People commit bug-fixes to\n'stable' (from which a release will be made later) and all new and\nexperimental stuff is tried on 'dev'. So there's a lot in 'dev' that's\nnot there in 'stable'.\n\n>\n> Another way to do it would be to use cherry-pick on a new branch:\n>\n>  git checkout -b new_topicA dev\n>  git cherry-pick stable..topicA\n\nHmmm...this looks safe to do. If I do \"git log stable..topicA\" it\nshould only show my commits made on top of stable, right? Or I can\neven mention the commit SHA here?\n\nThanks,\n-mandeep\n\n>\n> --\n> \\\\// Peter - http://www.softwolves.pp.se/\n"},{"id":"229275","messageId":"CAC+QLdQixg1+hGy2fiiS--R1vs3A6h5eD-y-FqPFZLHZ7cK0Qg@mail.gmail.com","threadId":"35176","inReplyTo":"CAGyf7-EDtNPhAGm21YmPSZfWmdjhKejhmoWNG3Au5LaorOodCw@mail.gmail.com","subject":"Re: Moving commits from one branch to another (improving my git fu!)","fromName":"Mandeep Sandhu","fromEmail":"mandeepsandhu.chd@gmail.com","sentAt":"2013-10-22T06:15:06Z","receivedAt":"2013-10-22T06:15:06Z","isPatch":false,"sender":{"key":"mandeepsandhu.chd@gmail.com","avatar":"https://gravatar.com/avatar/d85c7ffba588dd2ceaf57a974df7695a2fa7a10f3e6f5635549c9eb1b599a0db?d=mp&s=160"},"body":"On Tue, Oct 22, 2013 at 11:30 AM, Bryan Turner <bturner@atlassian.com> wrote:\n> A quick glance at your command line and the man page for git rebase\n> suggests the problem was you didn't actually use --onto. I believe the\n> correct command would be:\n>\n> git rebase --onto dev stable topicA\n\nYes, thats the cmd I gave. (missed typing onto in the mail though)\n>\n>\n> That should start by determining which commits are one topicA but not\n> stable and then checkout dev and apply those new commits.\n\nThats what I expected too. There are only 2 commits that were made in\ntopicA. So I was expecting it to pick those 2 and apply them on the\ndev branch. But instead it's applying a LOT of commits on dev.\nRemember that 'dev' is very different from 'stable'.\n\nAs suggested, maybe cherry-pciking is what I need to do.\n\nThanks,\n-mandeep\n\n\n>\n>\n> Hope this helps,\n> Bryan Turner\n>\n> On 22 October 2013 16:38, Mandeep Sandhu <mandeepsandhu.chd@gmail.com> wrote:\n>> Hi All,\n>>\n>> I'm in a bit of a pickle! :) So I've come to ask for help from the guru's here.\n>>\n>> My story is not unique but somehow the various suggested solutions\n>> don't seem to work in my case.\n>>\n>> * I was working on a feature which was supposed to be done off our\n>> 'dev' branch. But instead I forgot and branched out my topic branch\n>> from master (or as we call it 'stable').\n>> * I did 2 commits and finished off my work. Only later realizing that\n>> it had to be done off 'dev'.\n>> * Now I want to move my 2 commits (which are the top 2 commits on my\n>> topic branch) to a new branch which is branched off 'dev'.\n>>\n>> $ git branch\n>> * topicA\n>> * stable\n>> * dev\n>>\n>> topicA was based on stable. But now I want to base it dev.\n>>\n>> So I did what was most suggested, i.e use 'git rebase --onto'.\n>>\n>> Here's what I did when I was in topicA:\n>>\n>> $ git rebase dev stable topicA\n>> (this was suggested in the manpage as well).\n>>\n>> This started off a massive rebase operation, because the 'dev' branch\n>> is vastly diverged from stable, and a lot of conflicts started\n>> appearing.\n>>\n>> I'm not sure if I'm doing it right here, so can anyone suggest whether\n>> this is right or do I need to do it differently?\n>>\n>> PS: Please CC me (mandeepsandhu.chd@gmail.com) in your reply as I'm\n>> not currently subscribed to the list.\n>>\n>> Thanks for your time.\n>>\n>> Regards,\n>> -mandeep\n>> --\n>> To unsubscribe from this list: send the line \"unsubscribe git\" in\n>> the body of a message to majordomo@vger.kernel.org\n>> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n"},{"id":"229286","messageId":"87d2mx1nq1.fsf@sanitarium.localdomain","threadId":"35176","inReplyTo":"CAC+QLdSjTjftgUBy-1cHbATZnX-UO3PavUaLwErhCaxBa-hPmQ@mail.gmail.com","subject":"Re: Moving commits from one branch to another (improving my git fu!)","fromName":"Noufal Ibrahim","fromEmail":"noufal@nibrahim.net.in","sentAt":"2013-10-22T12:42:14Z","receivedAt":"2013-10-22T12:42:14Z","isPatch":false,"sender":{"key":"noufal@nibrahim.net.in","avatar":null},"body":"Mandeep Sandhu <mandeepsandhu.chd@gmail.com> writes:\n\n> Hi All,\n>\n> I'm in a bit of a pickle! :) So I've come to ask for help from the guru's here.\n>\n> My story is not unique but somehow the various suggested solutions\n> don't seem to work in my case.\n>\n> * I was working on a feature which was supposed to be done off our\n> 'dev' branch. But instead I forgot and branched out my topic branch\n> from master (or as we call it 'stable').\n> * I did 2 commits and finished off my work. Only later realizing that\n> it had to be done off 'dev'.\n> * Now I want to move my 2 commits (which are the top 2 commits on my\n> topic branch) to a new branch which is branched off 'dev'.\n\nI had a situtation similar to this a while ago and used the --onto\noption to rebase. The details are at \nhttp://nibrahim.net.in/2012/01/09/moving_topic_branches_in_git.html\n\n[...]\n\n\n-- \nCordially,\nNoufal\nhttp://nibrahim.net.in\n"},{"id":"229282","messageId":"CAC+QLdS-DFdQpkhFZ4ZTV_zLk0gst3FgNd+EFcX=8Qgpf2ZdOg@mail.gmail.com","threadId":"35176","inReplyTo":"87d2mx1nq1.fsf@sanitarium.localdomain","subject":"Re: Moving commits from one branch to another (improving my git fu!)","fromName":"Mandeep Sandhu","fromEmail":"mandeepsandhu.chd@gmail.com","sentAt":"2013-10-22T12:51:59Z","receivedAt":"2013-10-22T12:51:59Z","isPatch":false,"sender":{"key":"mandeepsandhu.chd@gmail.com","avatar":"https://gravatar.com/avatar/d85c7ffba588dd2ceaf57a974df7695a2fa7a10f3e6f5635549c9eb1b599a0db?d=mp&s=160"},"body":"Thanks for the link.\n\nI too tried doing a rebase with --onto, though as I said, I was\ngetting a lot of conflicts while doing it.\n\nSo cherry-picking my 2 commits was the solution that worked. I had\nalso screwed up my topic branch by doing different combo's of this cmd\nand using --set-upstream-to option to point to 'dev' on a branch that\nwas branched off from 'stable'! :)\n\nLesson learned. I'll be careful when doing branching next time :)\n\n-mandeep\n\n\n\nOn Tue, Oct 22, 2013 at 6:12 PM, Noufal Ibrahim <noufal@nibrahim.net.in> wrote:\n> Mandeep Sandhu <mandeepsandhu.chd@gmail.com> writes:\n>\n>> Hi All,\n>>\n>> I'm in a bit of a pickle! :) So I've come to ask for help from the guru's here.\n>>\n>> My story is not unique but somehow the various suggested solutions\n>> don't seem to work in my case.\n>>\n>> * I was working on a feature which was supposed to be done off our\n>> 'dev' branch. But instead I forgot and branched out my topic branch\n>> from master (or as we call it 'stable').\n>> * I did 2 commits and finished off my work. Only later realizing that\n>> it had to be done off 'dev'.\n>> * Now I want to move my 2 commits (which are the top 2 commits on my\n>> topic branch) to a new branch which is branched off 'dev'.\n>\n> I had a situtation similar to this a while ago and used the --onto\n> option to rebase. The details are at\n> http://nibrahim.net.in/2012/01/09/moving_topic_branches_in_git.html\n>\n> [...]\n>\n>\n> --\n> Cordially,\n> Noufal\n> http://nibrahim.net.in\n"}]}