混帐创建打上补丁(git create patch with diff)

2019-08-22 20:23发布

我想这样做

git diff 13.1_dev sale_edit > patch.diff

然后我试图做git apply patch.diff另外一个分支,但我得到了修补程序不适用。 如何从我可以用git使用适用的diff创建补丁文件?

收到错误:

$ 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上尝试这种

Answer 1:

尝试:

git apply --ignore-space-change --ignore-whitespace patch.diff

正如提到的“ 混帐:修补程序不适用 ”,这可以由以下原因造成:

  • 行尾的本地文件系统和远程回购之间不同。
    用户core.eol.gitattributes文件是一个好方法(见“ 上提交的git力文件编码 ”)
  • 执行位( ' x ')。
    这可能会导致你设置git config core.filemode false ,随后git reset --hard HEAD (确保你没有提交的修改,否则会被丢失)。


Answer 2:

您可以将补丁的3路合并:

git diff 13.1_dev sale_edit > patch.diff
git apply -3 patch.diff

它应该弹出的冲突,以便您可以手动解决。 或者你可以用一个班轮去,管道补丁直接混帐申请:

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...


Answer 3:

在这里,你有你已经用Diff分支来试试吧。

git diff 13.1_dev sale_edit > patch.diff yourBranch()


Answer 4:

使用Git版本1.9.1,我看到过类似的投诉时,使用“git的申请”申请使用“git的差异”创建补丁。

这似乎1.9.1 Git是其处理的补丁文件空间和制表符混合问题。

warning: squelched 1 whitespace error warning: 6 lines add whitespace errors.

@ VonC的回答没有帮助,我仍然得到同样的警告。

最简单的解决方案是简单地使用,成功地应用于“git的差异”输出到目标的git目录捕捉所有更改“ 补丁 ”指令。

$ patch --version GNU patch 2.7.1



文章来源: git create patch with diff
标签: git patch