linux - 补丁:以非交互模式运行

标签 linux unix patch

我想自动测试一组仍然干净利落地适用于(更新的)代码库的补丁。为此,我打算运行

patch -p 1 < path/to/patch0.patch

对于所有补丁 patch*.patch,检查此命令的返回码,并将其存储在某处。不幸的是,patch 在某些情况下似乎可以交互工作。需要交互的典型输出是

can't find file to patch at input line 44
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|Index: foo/docs/faq.html
|===================================================================
|--- foo.orig/docs/faq.html
|+++ foo/docs/faq.html
--------------------------
File to patch: 

有没有办法以非交互方式运行 patch? (也许 patch 不是完成这里任务的正确工具。)

最佳答案

使用-f(--force)选项:

echo a > a
echo b > b
diff -Nu a b > p
rm a b
patch -p 1 < p
can't find file to patch at input line 3
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|--- a  2016-05-11 16:16:24.115481324 +0700
|+++ b  2016-05-11 16:16:24.115481324 +0700
--------------------------
File to patch: 

(要求输入)。然而,

patch -f -p 1 < p
can't find file to patch at input line 3
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|--- a  2016-05-11 16:16:24.115481324 +0700
|+++ b  2016-05-11 16:16:24.115481324 +0700
--------------------------
No file to patch.  Skipping patch.
1 out of 1 hunk ignored

以退出状态 ($?) 1 退出:

echo $?
1

关于linux - 补丁:以非交互模式运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37157658/

相关文章:

bash - 读取 unix 上的文件列表并运行命令

php - Magento 补丁安装失败

svn - 创建一个包含新目录的 SVN 补丁

linux - 在 google-chrome 中打开标准流

unix - 仅打印匹配的单词,而不是通过grep打印整行

bash - 如何在不更改 $PATH 的情况下重新加载 .bash_profile?

linux - 创建显示较少删除行的补丁

linux - 获取子进程的段错误回溯

Linux:如何从包含原始模式和新模式的文件中替换文件名?

linux - 关于 grep 命令