步驟:用git提交patch,併發送郵件列表

一. 先配置git send-mail 的 smtp服務器:
1. 安裝git-email:
# apt-get install git git-core git-email

修改gitconfig文件:vim ~/.gitconfig

[color]
ui = auto
[commit]
template = ~/.commit_template
[user]
name = ***
email = ***@***.com
[alias]
pretty = log --branches --remotes --tags --graph --oneline
--decorate
[sendemail]
smtpencryption = tls
smtpserver = smtp.gmail.com
smtpuser = *****.****@gmail.com
smtpserverport = 587
smtppass = abcdef

suppresscc = all //will suppress all auto cc values
confirm = always
#to = *****.****@gmail.com //Specify the primary recipient
#cc = s***[email protected] //CC list


2. Then edit the .git/hooks/pre-commit file to contain only the following two lines:

#!/bin/sh
exec git diff --cached | scripts/checkpatch.pl --no-signoff - || true


二. 好了,下面就是提交的步驟了。
1. 按功能分類提交commit ,提交之前先執行腳本 ./scripts/cleanfile xx.  

  • 加-s選項,自動Signed-off-by.

  • git commit --amend --author " Xxx Zhang "(添加實際的author,如果author是本人,則不要寫)

  • commit message 第一行要是patch的主題(包括patch的從屬子系統,和概述),第二行是patch的詳細描述。

  • 如果想修改其中的一個commit:
         a)git format-patch -n
         b)git reset到那個commit,如要更改或添加某個文件,git add; 如要刪除某個commit的文件,(git reset HEAD^ file),然後 commit --amend
         c)git am *.patch (不用git apply,因爲apply命令只將patch應用到index,而不會將commit message同時應用到git倉庫上。如果當前目錄下之前執行過git-am,而沒有發送email,需要先執行git am --abort放棄掉之前的am信息。遇到了一次abort不掉的時候,執行rm -rf .git/rebase-apply/就可以了,參照如下Linkhttp://git.661346.n2.nabble.com/Dangerous-quot-git-am-abort-quot-behavior-td5853324.html)

2. 生成patch:

  • git format-patch -2 --cover-letter//2表示從HEAD的commit開始,向前生成兩個commit的patch。--cover-letter會生成一個0000-cover-letter.patch,格式和commit message類似,第一行是patchset的主題,第二行描述這組patchset的詳細信息,它就是郵件中的【PATCH 0/n】(有必要的話,將測試結果和基於的主線版本寫在0000-cover-letter.patch中的詳細描述中)。

  • git format-patch -numbered --cover-letter --subject-prefix="PATCH v2" (如果不是第一版   patch需要添加版本號,以v2爲例)


3. 檢查patch:
  ./scripts/checkpatch.pl 0001-nfs-add-a-pr_info.patch (不用檢查0000-cover-letter.patch)


4. 發郵件列表:
  git send-email *.patch
  如果想要編輯patch郵件內容,加--annotate選項。
  編輯完一個退出vim用:wn命令,編輯下一個patch,直到最後一個直接wq退出vim即可。

$ git send-email *.patch
/tmp/59yD80Mjvb/0000-cover-letter.patch
/tmp/59yD80Mjvb/0001-clone-patch-test-001.patch
/tmp/59yD80Mjvb/0002-revised-text.patch
3 files to edit
Who should the emails appear to be from? [chunyan.zhang ]zh**.****@gmail.com//輸入發件人郵箱
Emails will be sent from: [email protected]
Who should the emails be sent to? z***@gmail.com //輸入收件人郵箱
Message-ID to be used as In-Reply-To for the first email?for_test//隨便輸入一個ID


附:標準的patch格式
The canonical patch subject line is:

Subject: [PATCH 001/123] subsystem: summary phrase

The canonical patch message body contains the following:

- A "from" line specifying the patch author.

- An empty line.

- The body of the explanation, which will be copied to the
permanent changelog to describe this patch.

- The "Signed-off-by:" lines, described above, which will
also go in the changelog.

- A marker line containing simply "---".

- Any additional comments not suitable for the changelog.

- The actual patch (diff output).


參考:
http://www.freedesktop.org/wiki/Software/PulseAudio/HowToUseGitSendEmail/
http://blog.chinaunix.net/uid-28453894-id-3552774.html
http://kernelnewbies.org/OPWfirstpatch


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章