1使用git format-patch產生所需要的patch:
當前分支所有超前master的提交:
git format-patch -M master
某次提交以後的所有patch:
git format-patch 4e16 --4e16指的是commit名
從根到指定提交的所有patch:
git format-patch --root 4e16
某兩次提交之間的所有patch:
git format-patch 365a..4e16 --365a和4e16分別對應兩次提交的名稱
某次提交(含)之前的幾次提交:
git format-patch –n 07fe
--n指patch數,07fe對應提交的名稱
故,單次提交即為:
git format-patch -1 07fe
git format-patch產生的補丁檔案預設從1開始順序編號,並使用對應提交資訊中的第一行作為檔案名稱。如果使用了-- numbered-files選項,則檔案名稱只有編號,不包含提交資訊;如果指定了--stdout選項,可指定輸出位置,如當所有patch輸出到一個檔案;可指定-o <dir>指定patch的存放目錄;
2應用patch:
先檢查patch檔案:git apply --stat newpatch.patch
檢查能否應用成功:git apply --check newpatch.patch
打補丁:git am --signoff < newpatch.patch
(使用-s或--signoff選項,可以commit資訊中加入Signed-off-by資訊)
如果應用patch出現問題:參考git am PATCH 失敗的處理方法http://blog.csdn.net/sunnylgz/article/details/7660638
參考資料:
git-format-patch(1) - Linux man page http://linux.die.net/man/1/git-format-patch
How to create and apply a patch with Git http://ariejan.net/2009/10/26/how-to-create-and-apply-a-patch-with-git