[英]git create patch with diff
我試過了
git diff 13.1_dev sale_edit > patch.diff
然后我嘗試在另一個分支中執行git apply patch.diff
,但是我得到補丁不適用。 如何從差異中創建補丁文件,我可以使用git apply?
收到的錯誤:
$ git apply --ignore-space-change --ignore-whitespace diff.diff
diff.diff:9: trailing whitespace.
diff.diff:10: trailing whitespace.
function set_change_sale_date()
diff.diff:12: space before tab in indent.
$this->sale_lib->set_change_sale_date($this->input->post('change_sale_date'));
diff.diff:14: trailing whitespace.
diff.diff:15: trailing whitespace.
function set_change_sale_date_enable()
warning: application/controllers/sales.php has type 100755, expected 100644
error: patch failed: application/controllers/sales.php:520
error: application/controllers/sales.php: patch does not apply
warning: application/language/english/sales_lang.php has type 100755, expected 100644
error: patch failed: application/language/english/sales_lang.php:134
error: application/language/english/sales_lang.php: patch does not apply
warning: application/libraries/Sale_lib.php has type 100755, expected 100644
error: patch failed: application/models/sale.php:170
error: application/models/sale.php: patch does not apply
warning: application/views/sales/register.php has type 100755, expected 100644
error: patch failed: application/views/sales/register.php:361
error: application/views/sales/register.php: patch does not apply
我在Mac上嘗試這個
試試:
git apply --ignore-space-change --ignore-whitespace patch.diff
正如“ git:patch不適用 ”中所述,這可能是由以下原因引起的:
.gitattributes
文件中的用戶core.eol
是一種很好的方法(參見“ 提交時的git force文件編碼 ”) x
')。 git config core.filemode false
,然后是git reset --hard HEAD
(確保您沒有未提交的更改,否則它們將丟失)。 您可以將修補程序應用為3向合並:
git diff 13.1_dev sale_edit > patch.diff
git apply -3 patch.diff
它應該提出沖突,以便您可以手動解決。 或者你可以使用單線,將補丁直接用於git-apply:
git diff 13.1_dev sale_edit | git apply -3
要反轉補丁:
git diff 13.1_dev sale_edit | git apply -3 -R
(注意:這與上面的命令相同,沒有創建補丁文件的兩階段過程)
git help apply
-3, --3way
When the patch does not apply cleanly, fall back on 3-way merge if
the patch records the identity of blobs it is supposed to apply to,
and we have those blobs available locally, possibly leaving
the conflict markers in the files in the working tree for the user
to resolve...
在這里你必須嘗試與你有差異的分支。
git diff 13.1_dev sale_edit > patch.diff yourBranch()
使用git版本1.9.1,我在使用'git apply'來應用使用'git diff'創建的補丁時會看到類似的抱怨。
似乎1.9.1 git在補丁文件中處理空格和制表符混合的問題。
warning: squelched 1 whitespace error warning: 6 lines add whitespace errors.
@ VonC的回答沒有幫助,我仍然得到同樣的警告。
最簡單的解決方案是簡單地使用' patch '命令,該命令成功地將'git diff'輸出中捕獲的所有更改應用到目標git目錄。
$ patch --version GNU patch 2.7.1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.