git patch 使用

來源:互聯網
上載者:User

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.