I'm trying to use the normal format to create a patch and then apply it. Despite -n
on both diff
and patch
, and an explicit file output -o
on patch
, I get the error:
我尝试使用正常的格式来创建一个补丁,然后应用它。尽管在diff和patch上都有-n,并且在patch上有一个显式的文件输出-o,我得到了错误:
patch: **** Only garbage was found in the patch input.
How can I solve this? I can't use unified or context patches in this case, so that's not a solution.
我怎么解决这个问题呢?在这种情况下,我不能使用统一的或上下文的补丁,所以这不是一个解决方案。
Is it a bug or something? Editor format seems to work, for some reason:
是虫子还是什么?由于某种原因,编辑器格式似乎起了作用:
$ echo a > a.txt
$ echo b > b.txt
$ diff -n a.txt b.txt > ab.diff
$ patch -n -o a.txt a.txt ab.diff
patch: **** Only garbage was found in the patch input.
$ diff -e a.txt b.txt > ab.diff
$ patch -e -o a.txt a.txt ab.diff
$ diff a.txt b.txt
$
This is on Linux Mint 16, with:
这是在Linux Mint 16上的:
$ diff --version
diff (GNU diffutils) 3.2
$ patch --version
GNU patch 2.7.1
1 个解决方案
#1
3
According to the man page of diff
, you are not using the normal diff format with -n
but the RCS one:
根据diff的手册页,您没有使用-n的正常的diff格式,但是RCS one:
-n --rcs Output an RCS format diff.
In order to use the normal format you can use the --normal
option. In the patch
command instead -n
specifies the normal mode. So it's not a bug, more an unhappy naming convention.
为了使用正常的格式,您可以使用-normal选项。在patch命令中,-n指定了正常模式。所以这不是一个错误,更多的是不愉快的命名约定。
Example
$ echo a > a.txt
$ echo b > b.txt
$ diff --normal a.txt b.txt > ab.diff
$ patch --normal a.txt ab.diff
$ diff a.txt b.txt
$
(You can avoid the --normal
flags since they are the default format for both the commands)
(您可以避免——普通标志,因为它们是命令的默认格式)
#1
3
According to the man page of diff
, you are not using the normal diff format with -n
but the RCS one:
根据diff的手册页,您没有使用-n的正常的diff格式,但是RCS one:
-n --rcs Output an RCS format diff.
In order to use the normal format you can use the --normal
option. In the patch
command instead -n
specifies the normal mode. So it's not a bug, more an unhappy naming convention.
为了使用正常的格式,您可以使用-normal选项。在patch命令中,-n指定了正常模式。所以这不是一个错误,更多的是不愉快的命名约定。
Example
$ echo a > a.txt
$ echo b > b.txt
$ diff --normal a.txt b.txt > ab.diff
$ patch --normal a.txt ab.diff
$ diff a.txt b.txt
$
(You can avoid the --normal
flags since they are the default format for both the commands)
(您可以避免——普通标志,因为它们是命令的默认格式)