Re: Commited to wrong branch

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Martin,

I'm pretty shocked how difficult this is... still...

I'm finding git logs and reflogs pretty difficult to read and
interpret (head melting) - in particular telling what happened on what
branch - but looking at the reflog (which I assume is showing me the
actions on the current branch, but I'm not sure) I think I must have
made two commits on the wrong branch so the reset has only 'popped'
the top one. Other than that your interpretation is correct.

I cannot currently change branches - it only complains about one file.
I'm a bit worried about that - I would like to understand why this is
a problem but I don't.

So I am now a little hazy on how to deal with previous TWO commits.

Sorry for misery.... I've lost the plot a bit here :-)

Howard



2009/9/15 Martin Langhoff <martin.langhoff@xxxxxxxxx>:
> On Tue, Sep 15, 2009 at 12:31 PM, Howard Miller
> <howard@xxxxxxxxxxxxxxxxxxx> wrote:
>> I am resurrecting a discussion from a week or two back (been on
>> holiday).  As follows...
>>
>> I had made some changes to some files and then done a commit. Only
>> then did I realise that I had the wrong branch checked out. To make
>> matters worse I then did a 'git reset HEAD^' which means that I can
>> now no longer switch branches. I am stuck. I had some advice (thanks!)
>> but it was not complete. I'd appreciate some more help.
>
> Hi Howard,
>
> just to make sure I understand your issue
>
>  1 - you were on branch X, thinking your were on branch Y
>  2 - edit, diff, commit, realised the mistake
>  3 - git reset HEAD^
>
> so if you now run `git status` and `git diff` it will show your
> changes as if they were uncommitted and unstaged.
>
> (Before you start with various attempts to recover below, a great
> trick is to make an instant-backup in case things go wrong: cd .. / ;
> cp -pr moodle.git moodle-backup.git ; cd moodle.git )
>
> You can now try do do
>
>  4 - git checkout Y
>
> and if the changes are on files that don't change between X and Y,
> then git will change the branches and keep your changes there. If the
> files are different between X and Y, it won't work.
>
> What I can recommend is to save your patch, as follows
>
>  5 - git diff > tempchanges.patch
>  6 - git reset --hard # this will discard your changes, careful
>  7 - git checkout Y
>  8 - patch -p1 < tempchanges.patch
>
> The patch may not apply cleanly :-) -- note that patch is more
> tolerant of iffy merges than git's internal implementation ("git
> apply") -- so it will succeed more often... but the results need
> review.
>
> There is a more git-style approach that is to use git-stash -- it uses
> git-apply and may not do what you want. The steps are
>
>  5a - git stash # will save your changed files into a "stashed commit"
> and clear out the changes from your working copy
>  6a - git checkout Y
>  7a - git stash apply
>
> hth,
>
>
>
> m
> --
>  martin.langhoff@xxxxxxxxx
>  martin@xxxxxxxxxx -- School Server Architect
>  - ask interesting questions
>  - don't get distracted with shiny stuff  - working code first
>  - http://wiki.laptop.org/go/User:Martinlanghoff
>
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]