How do we roll back to a branch using Git?

How do we roll back to a branch using Git?

by Jerry Lau -
Number of replies: 4

Hello there,

Running: Moodle 3.0.1+ (Build: 20160107), Redhat enterprise 6.6 64-bit, MySQL 5.5 and PHP 5.5.41


I was wondering if there is a way to roll back to a particular or previous branch via git. I believe there is but is not clear to me yet or wanted to confirm with more experienced individuals such as yourselves.

This is what I did:

[me@myserver moodle31]$ git reflog show

e8695a2 HEAD@{0}: HEAD@{6}: updating HEAD

9365405 HEAD@{1}: pull : Merge made by recursive.

908e9e7 HEAD@{2}: pull : Merge made by recursive.

2055b30 HEAD@{3}: pull : Merge made by recursive.

f84edd2 HEAD@{4}: pull : Merge made by recursive.

17848b8 HEAD@{5}: pull : Merge made by recursive.

7e6b733 HEAD@{6}: pull : Merge made by recursive.

e8695a2 HEAD@{7}: pull : Merge made by recursive.

fa8d72c HEAD@{8}: commit: merge devmoodle3 branch first time

6114fab HEAD@{9}: checkout: moving from master to MOODLE_30_STABLE

26653c8 HEAD@{10}: clone: from git://git.moodle.org/moodle.git

[me@myserver moodle31]$ git reset HEAD@{6}

However, when I load moodle, the page shows that the database will be updated. Was it because I tried to do a CLI command line upgrade but I did not say ":Y" though on the prompt.

Which brings me to my 2nd question. How do we roll back the database before upgrade actually starts in spite of the prompt.


[me@myserver moodle31]$  php /our/moodle31/path/admin/cli/upgrade.php

== Upgrading Moodle database from version 3.0.1+ (Build: 20151231) (2015111601.02) to 3.0.1+ (Build: 20160107) (2015111601.03) ==

Your Moodle files have been changed, and you are about to automatically upgrade your server to this version:

3.0.1+ (BUILD: 20160107) (2015111601.03)

Once you do this you can not go back again. Please note that this process can take a long time.

Are you sure you want to upgrade this server to this version?

type y (means yes) or n (means no)

Not sure how I can remove or eliminate that upgrading moodle warning before I can proceed.

Thanks






Average of ratings: -
In reply to Jerry Lau

Re: How do we roll back to a branch using Git?

by Emma Richardson -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

Anytime there is any change to Moodle, it will prompt you to "upgrade the database".

As for rolling back git, I will let a git expert answer that but, anytime that you want to go back to an earlier version of Moodle,  my understanding is that you are going to have to restore the database to a time when you had that version (which also means you will lose all data that has been added since that time). 

I am pretty sure that Moodle is not designed to go backwards, only forward!

In reply to Jerry Lau

Re: How do we roll back to a branch using Git?

by Ken Task -
Picture of Particularly helpful Moodlers

What does git branch -a show now?

Not a git expert, but wonder if one should then run a git pull again.

Did you check version.php file at code root to see what it says now?

If site has other plugins/addons, then one might have to manually 'roll' those back also ... which would be difficult considering the DB tables already have version numbers inserted .... good luck with that! :\

I'm in agreement with Emma here ... up or down, one should have begun the process of updating/upgrading with an sql dump of the DB AND a tar ball of the code runnning before git updates/upgrades.

IF you have a backup of the DB, restore that one, and let's see if the 'git rollback' actually worked.

BTW, this really should 'frighten' others from using git to install or update/upgrade.   It simply shows that no method of updating/upgrading is beyond issues ... WordPress's wp-cli, Joomla's built etc. can all have/develop issues.

'spirit of sharing', Ken

In reply to Jerry Lau

Re: How do we roll back to a branch using Git?

by Ken Task -
Picture of Particularly helpful Moodlers

First, don't think one can 'roll back' a moodle without having an SQL dump of the database that's at least the same version or close to (slightly higher than code) as the 'roll back' target.

Background ... back when folks were still transitioning from 1.9.x to a 2.x, many had a fresh 2.x install and 1.9.x backups they were restoring to their Moodle 2.x.   Someone discovered a way a 1.9 backup could be restored to a 2.x AND rid the course of legacy files.  Unfortunately, that 'bug' was closed in updates to Moodle 2 code.   So, to get the last version of Moodle that had the 'bug' one had to get a particular release of 2.3 - which was the last highest version of Moodle that had the ability to do the 'work-around' to restore 1.9 backups without legacy flies.

Caution ... if you attempt this, work with a copy of your production site ... copy of the current code that was installed via git, a copy of the DB, and a copy of the moodledata directory (just to be safe).

DO NOT TRY THIS ON A PRODUCTION SERVER!!!!

Here's an article I wrote on how I did that ... ie, get a specific older version of the Moodle code.

http://sos.tcea.org/cms/index.php/ken-s-korner/15-moodle-tips/116-executing-plan-to-restore-1-9-19-courses-to-a-version-2-x-legacy-issue

Again, think you'd have to have an SQL dump of the database that was very close to the version of code you are attempting to 'roll back' to ... actually, that sql dump would need to be slightly ahead of the code acquired (which would result in a minor update upwards).

This also doesn't do anything for plugins/addons ... just the core code.   Plugins/addons would prove to be problematic as they would have to be handled separately and not sure one could find old zips of plugins/addons unless you had downloaded and archived them.

So really ... the bottom line ... don't think you can 'roll back to a branch using Git' unless you have a 'matching' SQL dump.

'spirit of sharing', Ken

In reply to Ken Task

Re: How do we roll back to a branch using Git?

by Jerry Lau -

Thank you Emma and Ken.

That is what i suspect I would need to do.

The good thing is that this was just a test platform mirrored to our production. We have it set up that way so that if something breaks on the test, we can fix and expect that to happen in production. In the end, no surprises when we do the production upgrade.

Yes, I did do a backup and may be easier to just get a new branch and start from scratch LOL