GIT HELP REBASE - MASTER HAS DIVERGED

GIT HELP REBASE - MASTER HAS DIVERGED

by Mary Evans -
Number of replies: 14
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of 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

Average of ratings: -
In reply to Mary Evans

Re: GIT HELP REBASE - MASTER HAS DIVERGED

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of 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 big grin
In reply to Mary Evans

Re: GIT HELP REBASE - MASTER HAS DIVERGED

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of 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.

In reply to Tim Hunt

Re: GIT HELP REBASE - MASTER HAS DIVERGED

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of 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...sad

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

Cheers

Mary

Attachment GITK-TREE-20120202.jpg
In reply to Mary Evans

Re: GIT HELP REBASE - MASTER HAS DIVERGED

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of 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.

In reply to Tim Hunt

Re: GIT HELP REBASE - MASTER HAS DIVERGED

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

WOW! This worked first time!

All fixed! Thanks smile

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

Mary

In reply to Mary Evans

Re: GIT HELP REBASE - MASTER HAS DIVERGED

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of 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.)
In reply to Tim Hunt

Re: GIT HELP REBASE - MASTER HAS DIVERGED

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

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

I LOVE GIT!

Mary

In reply to Mary Evans

Re: GIT HELP REBASE - MASTER HAS DIVERGED

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

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

How about this London Underground map to revise your Shakespeare?

In reply to Joseph Rézeau

Re: GIT HELP REBASE - MASTER HAS DIVERGED

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of 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

In reply to Mary Evans

Re: GIT HELP REBASE - MASTER HAS DIVERGED

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of 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.)

In reply to Tim Hunt

Re: GIT HELP REBASE - MASTER HAS DIVERGED

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of 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

Attachment messed-up-MOODLE_23_STABLE.jpg
In reply to Mary Evans

Re: GIT HELP REBASE - MASTER HAS DIVERGED

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of 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

In reply to Tim Hunt

Re: GIT HELP REBASE - MASTER HAS DIVERGED

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Thanks Tim, I finally got it working again. smile