歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> 如何使用Git 發Patch

如何使用Git 發Patch

日期:2017/3/1 10:27:28   编辑:Linux編程

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

首先配置git。這裡有兩種配置文件,一個是全局的,在用戶的home目錄下,一個是相應git倉庫的。如果你設置了全局的,那麼可以用在各個git倉庫上。查看一下我已經配置好的配置文件:

www.linuxidc.com@linuxidc:~/qemu-kvm$ cat ~/.gitconfig
[user]
name = Wanpeng Li
email = [email protected]
[sendemail]
chainreplyto = false
smtpserver=/usr/bin/msmtp

我們可以使用命令來配置:

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

$git config --global user.name '[email protected]'

$git config --global sendemail.chainreplyto false

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

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

www.linuxidc.com@linuxidc:~/qemu-kvm$ cat ~/.msmtprc
account default
host ap.relay.ibm.com
#auth plain
user [email protected]
password xxxxx
from [email protected]


當你修改源碼文件後,使用git commit -a可以給你的patch加一些注釋,注意第一行添加的是patch的名字,然後空一行,然後另啟一行添加對patch的注釋。注意這patch的名字和注釋之前必須空一行。然後添加"Signed-off-by: "eg:

Signed-off-by: Wanpeng Li <[email protected]>


然後生成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,走出了第一步。

Copyright © Linux教程網 All Rights Reserved