如何使用Git 发Patch

2014-11-24 14:00:02 · 作者: · 浏览: 2

多发patch,多产生一些好的idea,才可以在open software community中越混越好。


首先配置git。这里有两种配置文件,一个是全局的,在用户的home目录下,一个是相应git仓库的。如果你设置了全局的,那么可以用在各个git仓库上。查看一下我已经配置好的配置文件:


我们可以使用命令来配置:


$git config --global user.name 'Wanpeng Li'


$git config --global user.name 'liwp@linux.vnet.ibm.com'


$git config --global sendemail.chainreplyto false


$git config --global sendemail.smtpserver /usr/bin/msmtp


另一个需要配置的就是msmtp的配置文件,如果没有安装msmtp使用apt-get install安装。



当你修改源码文件后,使用git commit -a可以给你的patch加一些注释,注意第一行添加的是patch的名字,然后空一行,然后另启一行添加对patch的注释。注意这patch的名字和注释之前必须空一行。然后添加"Signed-off-by: "eg:


Signed-off-by: Wanpeng Li



然后生成patch文件,使用命令git format-patch,eg:


$git format-patch origin


如果觉得这个commit不想要了用git reset:


$git reset HEAD^


然后发送出去:


要使用git-send-email之前先要apt-get install git-email



$git send-email --to xxx@xxx --to xxx@xxx --cc xxx@xxx xxxxx.patch


下面就是我发出的这个patch的截图,虽然比较烂的patch,但是学会了怎么发patch,走出了第一步。