GIT HELP REBASE - MASTER HAS DIVERGED

GIT HELP REBASE - MASTER HAS DIVERGED

de Mary Evans -
Número de respuestas: 14
Imagen de Core developers Imagen de Documentation writers Imagen de Peer reviewers Imagen de Plugin developers Imagen de Testers

Can anyone offer some help to get me out of the mess I am in with GIT.

Doing a simple "rebase" which I wrote wrongly in the first place has not messed up master big-style. The message I am getting when I do 'git checkout master' goes something like this...

Your branch and 'origin/master' have diverged, you have 59 and 98 different commit(s) each, respectively.

What would be my best course of action here.

When this happened a while back...I ended up trashing the lot and starting over...and that was really painful, so I want to avoid this if possible.

Thanks in advance,

Mary

Promedio de valoraciones: -
En respuesta a Mary Evans

Re: GIT HELP REBASE - MASTER HAS DIVERGED

de Howard Miller -
Imagen de Core developers Imagen de Documentation writers Imagen de Particularly helpful Moodlers Imagen de Peer reviewers Imagen de Plugin developers
Do you expect *your* version of master and the remote version to be different? If you expect them to be the same then you can just trash your branch and checkout a new one.

However, I expect that isn't the case. It all rather depends on what you think the situation should be.

I hate rebase gran sonrisa
En respuesta a Mary Evans

Re: GIT HELP REBASE - MASTER HAS DIVERGED

de Tim Hunt -
Imagen de Core developers Imagen de Documentation writers Imagen de Particularly helpful Moodlers Imagen de Peer reviewers Imagen de Plugin developers

I find gitk the most useful tool for working out what is going on with git. Try

gitk master origin/master HEAD &

and see what that looks like. If necssary, take a screen grab of the tree view at the top of the window, and attach it here.

En respuesta a Tim Hunt

Re: GIT HELP REBASE - MASTER HAS DIVERGED

de Mary Evans -
Imagen de Core developers Imagen de Documentation writers Imagen de Peer reviewers Imagen de Plugin developers Imagen de Testers

Thanks Tim,

Here is the tree I got using that code I scrolled down to where the branches diverged.

Looking at the tree it's ovious to see where the problem started, I made a mistake when rebasing MDL-30714 which, as you can see, is where the diversion starts...triste

Is this salvageable? Or do I cut my losses and do as Howard says?

Cheers

Mary

Adjunto GITK-TREE-20120202.jpg
En respuesta a Mary Evans

Re: GIT HELP REBASE - MASTER HAS DIVERGED

de Tim Hunt -
Imagen de Core developers Imagen de Documentation writers Imagen de Particularly helpful Moodlers Imagen de Peer reviewers Imagen de Plugin developers

Yes, it is salvagable. And being git, there are probably several ways to do it.

First, you want to get your master banch back to where it was (but keep a spare branch pointing at the old messed up version just in case. So:

git checkout master
git branch pointer_to_old_messed_up_master
git fetch upstream
git reset --hard upstream/master

(to make sure that what git is doing is what you think it is, I always keep gitk open when doing things like this, and constaly refresh the view to see what is going on.)

Now suppose you need one or more of the commits from the old messed up master branch. The easiest way to do that is probably using git cherry-pick:

git checkout -b MDL-30714_new
git cherry-pick <whatever the SHA1 hash of the commit you want is> 

gitk will tell you the SHA1 of any commit if you click on on, and you can copy/paste from there.

En respuesta a Tim Hunt

Re: GIT HELP REBASE - MASTER HAS DIVERGED

de Mary Evans -
Imagen de Core developers Imagen de Documentation writers Imagen de Peer reviewers Imagen de Plugin developers Imagen de Testers

WOW! This worked first time!

All fixed! Thanks sonrisa

What do I do with the pointer_to_old_messed_up_master?  Is it safe to delete...is it deletable even?

Mary

En respuesta a Mary Evans

Re: GIT HELP REBASE - MASTER HAS DIVERGED

de Tim Hunt -
Imagen de Core developers Imagen de Documentation writers Imagen de Particularly helpful Moodlers Imagen de Peer reviewers Imagen de Plugin developers
Once you are sure that you have saved everything you need from pointer_to_old_messed_up_master you can do git branch -D pointer_to_old_messed_up_master (Even then, there would be ways to get back those versions for some time, until the garbage collector comes along and really deletes them. If you ever delete something critical in git, then look up the docs on git reflog.)
En respuesta a Tim Hunt

Re: GIT HELP REBASE - MASTER HAS DIVERGED

de Mary Evans -
Imagen de Core developers Imagen de Documentation writers Imagen de Peer reviewers Imagen de Plugin developers Imagen de Testers

Thanks for all the help with this...it's like looking at the London Underground Timetable!

I LOVE GIT!

Mary

En respuesta a Mary Evans

Re: GIT HELP REBASE - MASTER HAS DIVERGED

de Joseph Rézeau -
Imagen de Core developers Imagen de Particularly helpful Moodlers Imagen de Plugin developers Imagen de Testers Imagen de Translators

Mary "... it's like looking at the London Underground Timetable!"

How about this London Underground map to revise your Shakespeare?

En respuesta a Joseph Rézeau

Re: GIT HELP REBASE - MASTER HAS DIVERGED

de Mary Evans -
Imagen de Core developers Imagen de Documentation writers Imagen de Peer reviewers Imagen de Plugin developers Imagen de Testers

This reminds me, Joseph, it is ages since I read any Shakespeare, other than sonnets, but it also reminds me it's time I visited London too...although I don't care much for the underground.

Thanks again

Mary

En respuesta a Mary Evans

Re: GIT HELP REBASE - MASTER HAS DIVERGED

de Tim Hunt -
Imagen de Core developers Imagen de Documentation writers Imagen de Particularly helpful Moodlers Imagen de Peer reviewers Imagen de Plugin developers

If you don't like the underground, then you might appreciate my mother's blog: http://londonbusesonebusatatime.blogspot.com/

(Apologies for the spam.)

En respuesta a Tim Hunt

Re: GIT HELP REBASE - MASTER HAS DIVERGED

de Mary Evans -
Imagen de Core developers Imagen de Documentation writers Imagen de Peer reviewers Imagen de Plugin developers Imagen de Testers

Hi Tim,

It looks like I am back agin trying to rebuild MOODLE_23_STABLE after doing the same silly thing as I did earlier this year, by rebasing MDL-35571_M23 incorrectly.

Would it be safe for me to do the same as you suggested earlier in this discussion, that of banishing the old_messed-up_ branch in this case MOODLE_23_STABLE and then getting a new updated version of upstrem MOODLE_23_STABLE...?

Attatched is the state of play with the diverged M23 branch as see using gitk MOODLE_23_STABLE origin/MOODLE_23_STABLE HEAD &

Hope you can help?

Oh...by the way I don't recall seeing the link to your mother's blog before. I was just reading her most recent post...absolutely fantastic! What a wonderful idea.

Cheers

Mary

Adjunto messed-up-MOODLE_23_STABLE.jpg
En respuesta a Mary Evans

Re: GIT HELP REBASE - MASTER HAS DIVERGED

de Tim Hunt -
Imagen de Core developers Imagen de Documentation writers Imagen de Particularly helpful Moodlers Imagen de Peer reviewers Imagen de Plugin developers

The quickest way to get your messed up MOODLE_23_STABLE branch back to origin/MOODLE_23_STABLE is (assuming that you are on your MOODLE_23_STABLE branch) to do

git reset --hard origin/MOODLE_23_STABLE

Note that that will remove any uncomitted changes that you have, so you should probably start with

git status

If there are changes you want to keep, then do 

git stash
git reset --hard origin/MOODLE_23_STABLE
git stash pop