使用diff文件添加Patch时出错

时间:2012-06-05 13:03:34

标签: linux diff patch

使用diff文件添加补丁时遇到一些问题。 我用这种方式使用两个C源创建了diff文件:

$diff gitrans.c.origin gifstrans > giftrans.diff

当我尝试使用diff文件创建补丁时,我得到了这个错误:

$patch -p1 < giftrans.diff
patch: **** Only garbage was found in the patch input.
有人可以帮帮我吗?我找不到解决方案。

2 个答案:

答案 0 :(得分:3)

您没有使用正确的语法。使用方式如下:

$diff -aNur gitrans.c.origin gifstrans > giftrans.diff

哪里

-a , treats it as text
-N , treats absent files as empty, useful if you want
     just changes of different existing files but not 
     for new files
-u , output as unified. This is need to fix you problem
-r , recursively, useful if you want diff directories

我总是忘记选项,因此我只记得 aNur 这个词。这很容易记住。

答案 1 :(得分:2)

您应该使用具有给定补丁语法的统一差异格式

$diff -u gitrans.c.origin gifstrans > giftrans.diff
$patch < giftrans.diff

或带有以下补丁语法的默认diff格式

$diff gitrans.c.origin gifstrans > giftrans.diff
$patch gitrans.c.origin giftrans.diff
相关问题