Note: You are currently viewing documentation for Moodle 2.2. Up-to-date documentation for the latest stable version is available here: Git FAQ.

Git FAQ

From MoodleDocs

Note: This article is a work in progress. Please use the page comments or an appropriate moodle.org forum for any recommendations/suggestions for improvement.



What is Git?

Git is a distributed revision control system. See Git for details.


How do I upgrade from 2.0 to 2.1 via Git?

How are your changes recorded in git? I guess there are two main options:

  1. You have not done anything, so git status shows them as uncommitted changes.
  2. You have committed them as a private branch (that is, in the past, you have done something like git checkout -b mycustomisations MOODLE_20_STABLE, and then git add ..., git commit ... several times.

If you are in state 1., get your self into state 2. by following the outline instructions I just gave. Then, to decide how to proceed, we really need to consider two sub-cases of 2: 2a. you have only done a few customisations on your mycustomisations branch, so it is a short branch. 2b. you have done many customisations on your mycustomisations branch, so it is a very long branch. In case 2a, it is probably easiest to build a new branch with your changes, starting from a clean check-out of Moodle 2.1. There are two ways to do this:

A. Using rebase:

git checkout mycustomisations
git rebase --onto MOODLE_21_STABLE MOODLE_20_STABLE

B. Using cherry-pick:

  1. git log MOODLE_20_STABLE...mycustomisations (this gives you a list of the commit hashes of your changes, then for each commit has do... )
  2. git cherry {commit hash}

For both A. and B. there may be merge conficts that you have to resolve. In case 2b, doing a rebase is probably not feasible, so your only option is to do

git checkout mycustomisations
git merge MOODLE_21_STABLE

but as you found there are quite a lot of merge conflicts you may have to resolve. However, before you start do something like

git diff --stat MOODLE_20_STABLE...mycustomisations

which should give you a summary of which files you have changed.

Then, once you have started the git merge, and have all the conflicts to deal with, you can quickly solve most of them. For any folder, or file, where the git diff --stat showed that you have not made any changes, you can resolve all the merge conflicts in that file or folder by doing git checkout --theirs folder/or/file/path git add folder/or/file/path

The approach that works for 2b will also work for 2a, if you prefer.

Source: Upgrading to 2.0 via Git

See also