{"thread":{"id":"20853","subject":"Commit to wrong branch. How to fix?","startedAt":"2009-09-04T15:54:55Z","lastAt":"2009-09-05T12:51:33Z","messageCount":7,"participants":["Howard Miller","Michael J Gruber","Erik Faye-Lund","Jakub Narebski"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"122440","messageId":"88A0A7C2-7DCB-45A3-B196-BED2A8AC9405@googlemail.com","threadId":"20853","inReplyTo":null,"subject":"Commit to wrong branch. How to fix?","fromName":"Howard Miller","fromEmail":"howardsmiller@googlemail.com","sentAt":"2009-09-04T15:54:55Z","receivedAt":"2009-09-04T15:54:55Z","isPatch":false,"sender":{"key":"howardsmiller@googlemail.com","avatar":"https://gravatar.com/avatar/69a7274bc5c4c66910b00e4ea6590e46e2325b53ff4807854f3ed469b49400b1?d=mp&s=160"},"body":"I commited to the wrong branch and I can't figure out what to do. To  \nmake matters worse I then did 'git reset HEAD^' which has made things  \nmuch worse. It didn't remove the commit and now I can't change  \nbranches. I'm utterly confused. Any help much appreciated!\n\nMoral - use git status liberally and read it carefully before doing  \nanything. A 'git undo\" command would be great is someone is feeling  \ngenerous :-) \n"},{"id":"122441","messageId":"4AA13DF4.4050604@drmicha.warpmail.net","threadId":"20853","inReplyTo":"88A0A7C2-7DCB-45A3-B196-BED2A8AC9405@googlemail.com","subject":"Re: Commit to wrong branch. How to fix?","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2009-09-04T16:19:00Z","receivedAt":"2009-09-04T16:19:00Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Howard Miller venit, vidit, dixit 04.09.2009 17:54:\n> I commited to the wrong branch and I can't figure out what to do. To  \n> make matters worse I then did 'git reset HEAD^' which has made things  \n> much worse. It didn't remove the commit and now I can't change  \n> branches. I'm utterly confused. Any help much appreciated!\n> \n> Moral - use git status liberally and read it carefully before doing  \n> anything. A 'git undo\" command would be great is someone is feeling  \n> generous :-) \n\nWhatever happens, don't panic ;)\n\nLet's say \"geesh\" is the branch on which you committed by mistake, and\nwhich you have reset.\n\ngit reflog geesh\n\nwhich show you what has happened to that branch lately. In particular,\nit will list the \"lost\" commit. (Most probably it is the same as geesh@{1}.)\n\ngit tag sigh sha1ofthatcommit\n\nwill assign the tag \"sigh\", so that it won't get lost by doing \"git gc\"\nor such. Now you can lean back!\n\nNext step is committing \"sigh\" to the right branch. Depends on how you\narrived at that commit. Did you commit the complete tree you wanted, or\ndid you apply a change to geesh which you rather had wanted applied to\nsome other branch?\n\nMichael\n"},{"id":"122450","messageId":"40aa078e0909041011s7639cccbqa758f17a56c61863@mail.gmail.com","threadId":"20853","inReplyTo":"4AA13DF4.4050604@drmicha.warpmail.net","subject":"Re: Commit to wrong branch. How to fix?","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@googlemail.com","sentAt":"2009-09-04T17:11:18Z","receivedAt":"2009-09-04T17:11:18Z","isPatch":false,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"On Fri, Sep 4, 2009 at 6:19 PM, Michael J\nGruber<git@drmicha.warpmail.net> wrote:\n> Let's say \"geesh\" is the branch on which you committed by mistake, and\n> which you have reset.\n>\n> git reflog geesh\n\nThat should be \"git reflog show geesh\", no?\n\n-- \nErik \"kusma\" Faye-Lund\nkusmabite@gmail.com\n(+47) 986 59 656\n"},{"id":"122456","messageId":"26ae428a0909041101h509ffa31odf3502228517043a@mail.gmail.com","threadId":"20853","inReplyTo":"4AA13DF4.4050604@drmicha.warpmail.net","subject":"Re: Commit to wrong branch. How to fix?","fromName":"Howard Miller","fromEmail":"howardsmiller@googlemail.com","sentAt":"2009-09-04T18:01:06Z","receivedAt":"2009-09-04T18:01:06Z","isPatch":false,"sender":{"key":"howardsmiller@googlemail.com","avatar":"https://gravatar.com/avatar/69a7274bc5c4c66910b00e4ea6590e46e2325b53ff4807854f3ed469b49400b1?d=mp&s=160"},"body":"Hi Michael,\n\nThanks for your help.\n\nI had modified a few files and then done a 'git commit -a'. It was\nonly after this that I did a status and realised that I had switched\nto a different branch (and forgotten). Unfortunately the branch I\nswitched to tracks a remote that is my stable release so I'm a bit\nprecious about it. If I forget again and push it, I'm in trouble :-)\nYes, I have done that before!!\n\nHoward\n\n2009/9/4 Michael J Gruber <git@drmicha.warpmail.net>:\n> Howard Miller venit, vidit, dixit 04.09.2009 17:54:\n>> I commited to the wrong branch and I can't figure out what to do. To\n>> make matters worse I then did 'git reset HEAD^' which has made things\n>> much worse. It didn't remove the commit and now I can't change\n>> branches. I'm utterly confused. Any help much appreciated!\n>>\n>> Moral - use git status liberally and read it carefully before doing\n>> anything. A 'git undo\" command would be great is someone is feeling\n>> generous :-)\n>\n> Whatever happens, don't panic ;)\n>\n> Let's say \"geesh\" is the branch on which you committed by mistake, and\n> which you have reset.\n>\n> git reflog geesh\n>\n> which show you what has happened to that branch lately. In particular,\n> it will list the \"lost\" commit. (Most probably it is the same as geesh@{1}.)\n>\n> git tag sigh sha1ofthatcommit\n>\n> will assign the tag \"sigh\", so that it won't get lost by doing \"git gc\"\n> or such. Now you can lean back!\n>\n> Next step is committing \"sigh\" to the right branch. Depends on how you\n> arrived at that commit. Did you commit the complete tree you wanted, or\n> did you apply a change to geesh which you rather had wanted applied to\n> some other branch?\n>\n> Michael\n>\n"},{"id":"122457","messageId":"26ae428a0909041103p4ecba8efvff6223f902e14f1a@mail.gmail.com","threadId":"20853","inReplyTo":"4AA13DF4.4050604@drmicha.warpmail.net","subject":"Re: Commit to wrong branch. How to fix?","fromName":"Howard Miller","fromEmail":"howardsmiller@googlemail.com","sentAt":"2009-09-04T18:03:59Z","receivedAt":"2009-09-04T18:03:59Z","isPatch":false,"sender":{"key":"howardsmiller@googlemail.com","avatar":"https://gravatar.com/avatar/69a7274bc5c4c66910b00e4ea6590e46e2325b53ff4807854f3ed469b49400b1?d=mp&s=160"},"body":"Sorry... meant to add. When I do a 'git log' on the current (wrong\nbranch) the commit I made is still at the top of the list. I must\nadmit I don't understand what 'reflog' is (more reading) - not heard\nof that before. I did ONE commit and ONE reset and then decided not to\ntouch it again :-)\n\nHoward\n\n2009/9/4 Michael J Gruber <git@drmicha.warpmail.net>:\n> Howard Miller venit, vidit, dixit 04.09.2009 17:54:\n>> I commited to the wrong branch and I can't figure out what to do. To\n>> make matters worse I then did 'git reset HEAD^' which has made things\n>> much worse. It didn't remove the commit and now I can't change\n>> branches. I'm utterly confused. Any help much appreciated!\n>>\n>> Moral - use git status liberally and read it carefully before doing\n>> anything. A 'git undo\" command would be great is someone is feeling\n>> generous :-)\n>\n> Whatever happens, don't panic ;)\n>\n> Let's say \"geesh\" is the branch on which you committed by mistake, and\n> which you have reset.\n>\n> git reflog geesh\n>\n> which show you what has happened to that branch lately. In particular,\n> it will list the \"lost\" commit. (Most probably it is the same as geesh@{1}.)\n>\n> git tag sigh sha1ofthatcommit\n>\n> will assign the tag \"sigh\", so that it won't get lost by doing \"git gc\"\n> or such. Now you can lean back!\n>\n> Next step is committing \"sigh\" to the right branch. Depends on how you\n> arrived at that commit. Did you commit the complete tree you wanted, or\n> did you apply a change to geesh which you rather had wanted applied to\n> some other branch?\n>\n> Michael\n>\n"},{"id":"122460","messageId":"m33a72lf0h.fsf@localhost.localdomain","threadId":"20853","inReplyTo":"26ae428a0909041103p4ecba8efvff6223f902e14f1a@mail.gmail.com","subject":"Re: Commit to wrong branch. How to fix?","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2009-09-04T18:51:48Z","receivedAt":"2009-09-04T18:51:48Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Howard Miller <howardsmiller@googlemail.com> writes:\n\n> I must admit I don't understand what 'reflog' is (more reading) - not heard\n> of that before.\n\nI'll try to explain it with some ASCII-art.\n\nLet's say that you had the following situation:\n\n  ...---A---B---C           <-- foo  <--- HEAD\n\nCurrent branch is named 'foo', and three last commits on it are named\nA, B, C.\n\nNow you create new commit (I assume that you comitted unwanted\nchanges; the recipe would be different (much simpler) if you have\nrealized that you are on wrong branch[1] before committing)\n\n[1] git aware shell prompt, countaing branch name, could help there\n\n  ...---A---B---C---X           <-- foo  <--- HEAD\n\nReflog records that commit in 'foo' reflog and in HEAD reflog\n\n  foo@{0}: X\n\n\nYou have realized that you are on wrong branch, and you did \n\"git reset --hard HEAD^\" (too early)\n\n  ...---A---B---C               <-- foo  <--- HEAD\n                 \\\n                  \\-X\n\nReflog records that fact (it records where tip of branch was)\n\n  foo@{0}: C\n  foo@{1}: X\n\n\nThen if you want to create new branch 'bar' with X, you would do\n\n $ git checkout -b bar foo@{1}\n\nIf you wanted to have this commit on some other existing branch, let's\ncall it 'baz', you would do instead (I think):\n\n $ git checkout baz\n $ git cherry-pick foo@{1}\n\nHTH (hope that helps).\n-- \nJakub Narebski\nPoland\nShadeHawk on #git\n"},{"id":"122514","messageId":"4AA25ED5.1020700@drmicha.warpmail.net","threadId":"20853","inReplyTo":"40aa078e0909041011s7639cccbqa758f17a56c61863@mail.gmail.com","subject":"Re: Commit to wrong branch. How to fix?","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2009-09-05T12:51:33Z","receivedAt":"2009-09-05T12:51:33Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Erik Faye-Lund venit, vidit, dixit 04.09.2009 19:11:\n> On Fri, Sep 4, 2009 at 6:19 PM, Michael J\n> Gruber<git@drmicha.warpmail.net> wrote:\n>> Let's say \"geesh\" is the branch on which you committed by mistake, and\n>> which you have reset.\n>>\n>> git reflog geesh\n> \n> That should be \"git reflog show geesh\", no?\n> \n\nYes, sorry. \"show\" is default, but only without a branch arg :|\n\nMichael\n"}]}