「系统管理员 GIT 指南」:修訂間差異

出自MoodleDocs
跳到:導覽、​搜尋
(以“{{Installing Moodle}} This page describes how to maintain a copy of Moodle on your production server which can easily be upgraded using Git. If you have customisatio...”为内容创建页面)
 
 
(未顯示同一使用者於中間所作的 2 次修訂)
第1行: 第1行:
{{Installing Moodle}}
{{Installing Moodle}}
This page describes how to maintain a copy of Moodle on your production server which can easily be upgraded using Git. If you have customisations of Moodle core code, you are advised to follow the instructions in the [[Development:Quick Git start guide for Moodle development|Quick Git start guide for Moodle development]].
这个页面用来描述如何在你安装 Moodle 的服务器上使用 GIT 来进行更新。


To get the most of of Git it is worth making the effort to understand its basic concepts - see the See also section below. It can be a bit of a learning curve, especially if you are used to CVS or Subversion.
如果你自定制了 Moodle 的核心代码,建议参考下面的指南:[[Development:Moodle 开发快速 Git 指南|Moodle 开发快速 Git 指南]]。


== Getting hold of Git (Windows, OSX, Linux and others) ==
希望能够比较熟练的使用 GIT,你需要熟悉一些概念,请参考下面的章节。


Support for Git was, up until recently, mostly confined to Linux but builds are now available for most popular operating systems:
如果你从来没有接触过 GIT 或者你使用过其他版本的版本控制服务器,例如 CVS 和 Subversion,这里还是有点学习曲线的。


* List of downloads from Git site - http://git-scm.com/download
== 获得 Git 命令行运行工具 (Windows, OSX, Linux 和其他类型操作系统) ==


Once you have downloaded and installed your OS relevant git installation, the git commands in this document should work with your operating system.
Git 版本控制服务器现在也越来越被广泛的使用了,最常用的是在 Linux 服务器上,但是目前 Git 也能够被主流操作系统支持了:


== Obtaining the code from Git ==
* Git 支持的操作系统和相关软件的下载 - http://git-scm.com/download


The command line version of Git is discussed here. Graphical clients are little more than wrappers around the command line version, so you should be able to deduce the correct parameters quite easily.
当你在你使用的操作系统中下载和安装好 Git 后,本页面使用的 Git 命令行也应该能够被正确使用。


You can find the official Moodle git repository at git://git.moodle.org/moodle.git (with an official clone at git://github.com/moodle/moodle.git). To initialize your local checkout, use
== 从 Git 上获得源代码 ==
 
这里我们讨论 GIT 的命令行工具,Git 的图形化工具也基本上基于命令行,你应该比较容易的来获得正确的安装参数。
 
Moodle 的官方 Git 仓库链接如下: git://git.moodle.org/moodle.git 同时 Moodle 官方也会将代码推送到 github 中,你依然可以使用下面的链接git://github.com/moodle/moodle.git)
 
使用下面的命令来初始化你本地的代码:
<pre>
<pre>
$ git clone git://git.moodle.org/moodle.git            (1)
$ git clone git://git.moodle.org/moodle.git            (1)
第24行: 第30行:
$ git checkout MOODLE_25_STABLE                  (4)
$ git checkout MOODLE_25_STABLE                  (4)
</pre>
</pre>
* The command (1) initializes the new local repository as a clone of the 'upstream' (i.e. the remote server based) moodle.git repository. The upstream repository is called 'origin' by default. It creates a new directory named ''moodle'', where it downloads all the files. This operation can take a while as it is actually getting the entire history of all Moodle versions
* 命令 (1) 用来初始化一个新的本地仓库,这个仓库被用来克隆远程的 Moodle Git 中保存的代码。远程仓库也被称为上游代码或者默认被称为原始代码。这里也同时会在你的当前路径下新建一个名为  ''moodle'' 目录,这个目录被用来下载所有的文件。文件的下载过程可能比较长,因为 Git 在获取 Moodle 的修改历史和 Moodle 的所有历史版本。
* The command (2) lists all available branches.
* 命令 (2) 列出了所有可用的分支。
* Use the command (3) to create a new local branch called MOODLE_25_STABLE and set it to track the remote branch MOODLE_25_STABLE from the upstream repository.
* 使用命令 (3) 来创建一个新的本地分支,这个本地分支被称为 MOODLE_25_STABLE 同时设置为与上游的 MOODLE_25_STABLE 分支同步。
* The command (4) actually switches to the newly created local branch.
* 命令 (4) 将会切换到创建的本地分支。
 
注意:Git 的每一个命令将会有很多的参数,这些参数可以比上面介绍的参数更有效的工作。你可以通过参考 Git 的相关文档来获得相关的帮助信息。
 
==Git 穿透防火墙==
 
Git 使用只读协议,这个有可能被你的防火墙所阻止。
 
Git 协议使用的端口是 9418。


Note that Git has a huge number of options for each command and it's actually possible to do the above process with a single command (left as an exercise!!).
如果你的机器中有这个问题,你可以使用 Github 的 http 方式进行下载 <nowiki>https://github.com/moodle/moodle.git</nowiki>。


==Git from behind a firewall==
这个方式下载可能速度比较慢,请尽量使用 Git 协议下载你的代码。


Git uses a read-only protocol that may be blocked by your firewall (port 9418). If this is a problem, you can use Github's http version <nowiki>https://github.com/moodle/moodle.git</nowiki>. It's a bit slower, so use the Git protocol if you can.
== 更新你的 Moodle 安装 ==


== Updating your installation ==
Moodle 开发小组通常在每周的星期一和星期二提交整合和测试过的代码。你可以在星期三的时候通过更新你的代码来安装所有的补丁。


The Moodle development team performs integration and testing of fixed bugs every Monday and Tuesday. On Wednesday you can install all patches by updating your code. Check the [http://git.moodle.org/gw?p=moodle.git;a=summary shortlog] to see if the official repository has been already updated or not.
查看修改日志,可以通过下面的地址:[http://git.moodle.org/gw?p=moodle.git;a=summary http://git.moodle.org/gw?p=moodle.git;a=summary] ,这个地址中的内容显示 Moodle 被更新了还是没有。


To update your code to the latest version (on the MOODLE_22_STABLE branch) '''all''' you have to do is:
为了将你的代码更新到最新版本,你可以执行下面的命令:
<pre>
<pre>
$ cd /path/to/your/moodle/
$ cd /path/to/your/moodle/
$ git pull
$ git pull
</pre>
</pre>
If this is a production site you should still consider the [[Upgrade]] instructions (e.g. take backups).
 
如果你运行的 Moodle 站点是生产环境,你应该考虑使用 Moodle 的升级安装,在安装之前请备份数据库。


== Installing a contributed extension from its Git repository ==
== Installing a contributed extension from its Git repository ==

於 2013年8月29日 (四) 02:47 的最新修訂

這個頁面用來描述如何在你安裝 Moodle 的伺服器上使用 GIT 來進行更新。

如果你自定製了 Moodle 的核心代碼,建議參考下面的指南:Moodle 開發快速 Git 指南

希望能夠比較熟練的使用 GIT,你需要熟悉一些概念,請參考下面的章節。

如果你從來沒有接觸過 GIT 或者你使用過其他版本的版本控制伺服器,例如 CVS 和 Subversion,這裏還是有點學習曲線的。

獲得 Git 命令行運行工具 (Windows, OSX, Linux 和其他類型作業系統)

Git 版本控制伺服器現在也越來越被廣泛的使用了,最常用的是在 Linux 伺服器上,但是目前 Git 也能夠被主流作業系統支持了:

當你在你使用的作業系統中下載和安裝好 Git 後,本頁面使用的 Git 命令行也應該能夠被正確使用。

從 Git 上獲得原始碼

這裏我們討論 GIT 的命令行工具,Git 的圖形化工具也基本上基於命令行,你應該比較容易的來獲得正確的安裝參數。

Moodle 的官方 Git 倉庫連結如下: git://git.moodle.org/moodle.git 同時 Moodle 官方也會將代碼推送到 github 中,你依然可以使用下面的連結git://github.com/moodle/moodle.git)。

使用下面的命令來初始化你本地的代碼:

$ git clone git://git.moodle.org/moodle.git                       (1)
$ cd moodle
$ git branch -a                                                   (2)
$ git branch --track MOODLE_25_STABLE origin/MOODLE_25_STABLE     (3)
$ git checkout MOODLE_25_STABLE                                   (4)
  • 命令 (1) 用來初始化一個新的本地倉庫,這個倉庫被用來克隆遠程的 Moodle Git 中保存的代碼。遠程倉庫也被稱為上游代碼或者默認被稱為原始代碼。這裏也同時會在你的當前路徑下新建一個名為 moodle 目錄,這個目錄被用來下載所有的文件。文件的下載過程可能比較長,因為 Git 在獲取 Moodle 的修改歷史和 Moodle 的所有歷史版本。
  • 命令 (2) 列出了所有可用的分支。
  • 使用命令 (3) 來創建一個新的本地分支,這個本地分支被稱為 MOODLE_25_STABLE 同時設置為與上游的 MOODLE_25_STABLE 分支同步。
  • 命令 (4) 將會切換到創建的本地分支。

注意:Git 的每一個命令將會有很多的參數,這些參數可以比上面介紹的參數更有效的工作。你可以通過參考 Git 的相關文檔來獲得相關的幫助信息。

Git 穿透防火牆

Git 使用只讀協議,這個有可能被你的防火牆所阻止。

Git 協議使用的端口是 9418。

如果你的機器中有這個問題,你可以使用 Github 的 http 方式進行下載 https://github.com/moodle/moodle.git。

這個方式下載可能速度比較慢,請儘量使用 Git 協議下載你的代碼。

更新你的 Moodle 安裝

Moodle 開發小組通常在每周的星期一和星期二提交整合和測試過的代碼。你可以在星期三的時候通過更新你的代碼來安裝所有的補丁。

查看修改日誌,可以通過下面的地址:http://git.moodle.org/gw?p=moodle.git;a=summary,這個地址中的內容顯示 Moodle 被更新了還是沒有。

為了將你的代碼更新到最新版本,你可以執行下面的命令:

$ cd /path/to/your/moodle/
$ git pull

如果你運行的 Moodle 站點是生產環境,你應該考慮使用 Moodle 的升級安裝,在安裝之前請備份數據庫。

Installing a contributed extension from its Git repository

This is one way to handle adding plugins from other Git repositories into your Moodle repository. Another way is to use Git Submodules. However, at the time of writing, this is one of Git's rougher features and should be regarded as an advanced option.

For example, let us say we want to install the Book module from its Git repository into our Moodle 2.2.

$ cd /path/to/your/moodle/
$ cd mod                                                          (1)
$ git clone git://github.com/skodak/moodle-mod_book.git book      (2)
$ cd book
$ git checkout -b MOODLE_22_STABLE origin/MOODLE_22_STABLE        (3)
$ git branch -d master                                            (4)

The command (1) changes the current directory into the mod folder of your local Moodle clone. The command (2) creates a new subdirectory book and makes a local clone of Petr Škoda's vanilla Book repository. The command (3) creates a new local branch that will track the remote branch with a Book version for Moodle 2.2. The command (4) deletes the master that was created automatically by git-clone in (2) as we do not want it in this production checkout.

Note: you should check first the compatibility of a module with your Moodle branch by asking directly to the Maintainer before cloning the repo or - if you want to guess it - by issueing the command below before running the command (3), in order to verify what is available among the branches:

$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/MOODLE_15_STABLE
  remotes/origin/MOODLE_17_STABLE
  remotes/origin/MOODLE_18_STABLE
  remotes/origin/MOODLE_19_STABLE
  remotes/origin/MOODLE_20_STABLE
  remotes/origin/MOODLE_21_STABLE
  remotes/origin/MOODLE_22_STABLE
  remotes/origin/master

This will avoid an error message when you issue the command (3) against a nonexistent branch, e.g.:

§ git checkout -b MOODLE_25_STABLE origin/MOODLE_25_STABLE
fatal: git checkout: updating paths is incompatible with switching branches.
Did you intend to checkout 'origin/MOODLE_25_STABLE' which can not be resolved as commit?

In this case you should ask the Mantainer, here Petr Škoda, if master is the correct branch for Moodle 2.3+ and he will reply that the Book module has been already integrated in Moodle starting from 2.3 so there's no need to install it usit git. Please, as a general rule, before asking the Mantainer for something you should check the online documentation.

Now it is wise to put the new directory mod/book/ to the list of ignored files of the main Moodle clone, otherwise a status of the main clone will keep reminding you that the new code has not been checked in.

$ cd /path/to/your/moodle/
$ echo /mod/book/ >> .git/info/exclude

To update your Moodle installation now, you must visit both Git repositories and pull changes from upstream.

$ cd /path/to/your/moodle/
$ git pull
$ cd mod/book
$ git pull

Writing a shell script with these lines in the root of Moodle installation is a very good idea. Otherwise it is easy to forget what Git repositories are there within the main Moodle repository.

See also

Moodle Docs
Moodle forum discussions
External resources