{"thread":{"id":"26711","subject":"Correcting forgetting to make a new branch","startedAt":"2011-03-11T15:31:18Z","lastAt":"2011-03-11T15:53:19Z","messageCount":5,"participants":["Howard Miller","Alexey Feldgendler","Matthieu Moy","Michael J Gruber"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"163228","messageId":"AANLkTi=fp=-pwi7Mj9TptP22mtP51bzq5UwTLRx9LnNB@mail.gmail.com","threadId":"26711","inReplyTo":null,"subject":"Correcting forgetting to make a new branch","fromName":"Howard Miller","fromEmail":"howard@e-learndesign.co.uk","sentAt":"2011-03-11T15:31:18Z","receivedAt":"2011-03-11T15:31:18Z","isPatch":false,"sender":{"key":"howard@e-learndesign.co.uk","avatar":"https://gravatar.com/avatar/ddb66c6a4a077e52b823ac5b04f33ab927cb90e2ab1eafedaeba07b1920bb99e?d=mp&s=160"},"body":"The scenario is that I have done work on a branch and made a number of\ncommits. What I wanted to do was to start a new branch before I made\nthese commits. Unfortunatel, I got distracted and forgot that I hadn't\ndone it.\n\nIs there are neat way to create the branch and 'move' the commits over?\n\nTYIA\n"},{"id":"163232","messageId":"op.vr6rgcqs56e9f9@xman.eng.oslo.osa","threadId":"26711","inReplyTo":"AANLkTi=fp=-pwi7Mj9TptP22mtP51bzq5UwTLRx9LnNB@mail.gmail.com","subject":"Re: Correcting forgetting to make a new branch","fromName":"Alexey Feldgendler","fromEmail":"alexeyf@opera.com","sentAt":"2011-03-11T15:46:50Z","receivedAt":"2011-03-11T15:46:50Z","isPatch":false,"sender":{"key":"alexeyf@opera.com","avatar":null},"body":"On Fri, 11 Mar 2011 16:31:18 +0100, Howard Miller  \n<howard@e-learndesign.co.uk> wrote:\n\n> The scenario is that I have done work on a branch and made a number of\n> commits. What I wanted to do was to start a new branch before I made\n> these commits. Unfortunatel, I got distracted and forgot that I hadn't\n> done it.\n>\n> Is there are neat way to create the branch and 'move' the commits over?\n\nJust create a new branch right where you are, it will be correct.\n\nHowever, the branch that was active before when you should have branched  \nwill have been unintentionally updated. To fix that, you'll need to move  \nthe old branch a few commits back:\n\ngit branch -f <old-branch> <where-it-was-before>\n\n\n-- \nAlexey Feldgendler\nSoftware Developer, Desktop Team, Opera Software ASA\n[ICQ: 115226275] http://my.opera.com/feldgendler/\n"},{"id":"163235","messageId":"4D7A4483.5080209@drmicha.warpmail.net","threadId":"26711","inReplyTo":"AANLkTi=fp=-pwi7Mj9TptP22mtP51bzq5UwTLRx9LnNB@mail.gmail.com","subject":"Re: Correcting forgetting to make a new branch","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2011-03-11T15:49:23Z","receivedAt":"2011-03-11T15:49:23Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Howard Miller venit, vidit, dixit 11.03.2011 16:31:\n> The scenario is that I have done work on a branch and made a number of\n> commits. What I wanted to do was to start a new branch before I made\n> these commits. Unfortunatel, I got distracted and forgot that I hadn't\n> done it.\n> \n> Is there are neat way to create the branch and 'move' the commits over?\n\nIt depends on which commit you wanted the new branch to start with. If\nyou have\n\n...-*-*-*-X-*-*-*-*-A\n\non branch A and X is the commit where you meant to create a new branch B\nstarting at X you can simply\n\ngit checkout A\ngit branch B\ngit reset --hard X\n\nor simply\n\ngit branch -m A B\ngit branch -f A X\n\nIf, on the other hand, you wanted to start B from a different commit Y,\nyou will need to rebase:\n\ngit branch B A\ngit branch -f A X\ngit rebase --onto Y A B\n\nAfter backing up, of course ;)\n\nMichael\n"},{"id":"163234","messageId":"vpqk4g57j1h.fsf@bauges.imag.fr","threadId":"26711","inReplyTo":"op.vr6rgcqs56e9f9@xman.eng.oslo.osa","subject":"Re: Correcting forgetting to make a new branch","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2011-03-11T15:50:50Z","receivedAt":"2011-03-11T15:50:50Z","isPatch":false,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"\"Alexey Feldgendler\" <alexeyf@opera.com> writes:\n\n> However, the branch that was active before when you should have\n> branched will have been unintentionally updated. To fix that, you'll\n> need to move the old branch a few commits back:\n>\n> git branch -f <old-branch> <where-it-was-before>\n\nThis is correct, but for completeness: don't do that if you've already\npushed your changes. If you pushed them and people already pulled them,\nyou can hardly do better than appologize to your co-workers that you\nshouldn't have done that, and possibly create a new commit on top of the\nbranch reverting what you did.\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"163236","messageId":"AANLkTikjonZxcHk3a4HvEhiDfcBqwgpqzFP2F=8tF7qv@mail.gmail.com","threadId":"26711","inReplyTo":"vpqk4g57j1h.fsf@bauges.imag.fr","subject":"Re: Correcting forgetting to make a new branch","fromName":"Howard Miller","fromEmail":"howard@e-learndesign.co.uk","sentAt":"2011-03-11T15:53:19Z","receivedAt":"2011-03-11T15:53:19Z","isPatch":false,"sender":{"key":"howard@e-learndesign.co.uk","avatar":"https://gravatar.com/avatar/ddb66c6a4a077e52b823ac5b04f33ab927cb90e2ab1eafedaeba07b1920bb99e?d=mp&s=160"},"body":"> \"Alexey Feldgendler\" <alexeyf@opera.com> writes:\n>\n>> However, the branch that was active before when you should have\n>> branched will have been unintentionally updated. To fix that, you'll\n>> need to move the old branch a few commits back:\n>>\n>> git branch -f <old-branch> <where-it-was-before>\n>\n> This is correct, but for completeness: don't do that if you've already\n> pushed your changes. If you pushed them and people already pulled them,\n> you can hardly do better than appologize to your co-workers that you\n> shouldn't have done that, and possibly create a new commit on top of the\n> branch reverting what you did.\n\nI hadn't (luckily), so that worked fine. Thanks for your help - both of you :)\n"}]}