Re: Commit to wrong branch. How to fix?
- From
Howard Miller <howardsmiller@googlemail.com>
- Date
- Sep 4, 2009, 18:03 UTC
- Message-ID
- <26ae428a0909041103p4ecba8efvff6223f902e14f1a@mail.gmail.com>
- In-Reply-To
- <4AA13DF4.4050604@drmicha.warpmail.net>
Sorry... meant to add. When I do a 'git log' on the current (wrong branch) the commit I made is still at the top of the list. I must admit I don't understand what 'reflog' is (more reading) - not heard of that before. I did ONE commit and ONE reset and then decided not to touch it again :-)
Howard
2009/9/4 Michael J Gruber <git@drmicha.warpmail.net>:
Show 32 quoted lines
> Howard Miller venit, vidit, dixit 04.09.2009 17:54:
>> I commited to the wrong branch and I can't figure out what to do. To
>> make matters worse I then did 'git reset HEAD^' which has made things
>> much worse. It didn't remove the commit and now I can't change
>> branches. I'm utterly confused. Any help much appreciated!
>>
>> Moral - use git status liberally and read it carefully before doing
>> anything. A 'git undo" command would be great is someone is feeling
>> generous :-)
>
> Whatever happens, don't panic ;)
>
> Let's say "geesh" is the branch on which you committed by mistake, and
> which you have reset.
>
> git reflog geesh
>
> which show you what has happened to that branch lately. In particular,
> it will list the "lost" commit. (Most probably it is the same as geesh@{1}.)
>
> git tag sigh sha1ofthatcommit
>
> will assign the tag "sigh", so that it won't get lost by doing "git gc"
> or such. Now you can lean back!
>
> Next step is committing "sigh" to the right branch. Depends on how you
> arrived at that commit. Did you commit the complete tree you wanted, or
> did you apply a change to geesh which you rather had wanted applied to
> some other branch?
>
> Michael
>