patch 命令无法创建新文件

patch 命令无法创建新文件

我正在测试 patch 命令并创建了两个目录,如下所示:

d1:

d2:
file1.txt

我使用 diff 创建了补丁文件并对其进行了修补:

diff -Naur d1 d2 > patchfile.txt
patch -p0 <patchfile.txt

但它没有创建 d1/file1.txt 并显示以下消息:

The next patch would create the file d2/file1.txt,
which already exists!  Assume -R? [n] n
Apply anyway? [n] n
Skipping patch.
1 out of 1 hunk ignored

我无法弄清楚这个问题,请帮助我。

补丁文件.txt:

--- d1/file1.txt    1969-12-31 19:00:00.000000000 -0500
+++ d2/file1.txt    2017-11-12 22:48:07.428873802 -0500
@@ -0,0 +1,3 @@
+a
+b
+c

答案1

diff -Naur d1 d2 > patchfile.txt
patch -p0 <patchfile.txt

... 你的意思:

cd d1; patch -p1 < ../patchfile.txt

毕竟,补丁文件包含已发生的更改(新文件d2)。告诉它执行已完成的操作毫无意义,不是吗?

相关内容