创建patch

How to create a patch

If you have made some changes to the code that you would like to share with the community, particularly if you want to send them to one of the core developers for possible inclusion in Moodle Core, it is very helpful if you can provide them as a patch file. Sometimes also called a diff file.

This page explains how you can make a patch file. Patch is a standard format, and there are many options for how to create one. Pick the one that is easiest for you. One of the most critical aspects of patch usage is identifying for your audience the location for the patch file for application relative to the -p flag! When you create patches note your location and provide that when you share patches.

Creating a patch using diff

diff is the a linux command line program, and is where patch files originated. It requires that you have two copies of the code, one with your changes, and one without. Suppose these two copies are in folders called 'standard_moodle' and 'my_moodle' which are subdirectories of the current folder. Then to create the patch, type:

diff -Naur standard_moodle my_moodle > patch.txt

Creating a patch using Eclipse

See Setting_up_Eclipse#Creating_a_patch. Eclipse makes creating patches really easy, once you have got it set up correctly.

Creating a patch using WinMerge

WinMerge is a nice windows GUI for comparing folders. In this sense it is like the original command-line 'diff' program. You need a copy of 'standard_moodle' and 'my_moodle'. Use File -> Open... to open the two versions for comparison. This will give you a nice view of what you have changed. Then do Tools -> Generate patch .... In the dialogue box, make sure you select Style: Unified in the Format box.

Creating a patch using Git

Creating a patch if you're using Git for version control is similar to CVS, and similarly you don't need an unchanged copy of moodle to diff against.

There are several ways for creating a patch, the recommended one is using git format-patch (as mentioned in MDL-43119)

The easiest way to create a patch for the last commit is

git show > patch.txt

or if you want to create a patch between 2 specific commits you can use git diff

git diff commitid1 commitid2 > patch.txt

There's also a tool, format-patch, for formatting a patch to send as an e-mail. You can create patches for the last n revisions like this:

git format-patch -n

which will create the patch in the current directory. The -o parameter allows you to specify a different output directory.

See Also

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值