在Linux中使用不同目录中的文件应用补丁命令

发布于 2024-10-07 23:43:09 字数 727 浏览 0 评论 0原文

我正在尝试使用不同目录中的 2 个文件来应用补丁。输出文件也应该位于不同的目录中。第一个文件位于 /var/local/documents/document.xml 中,补丁文件位于 /var/local/patches/patch.diff 中,我想要输出文件应在 /var/local/final/final.xml 中创建。

当文件位于同一目录中时,此命令有效:

patch document.xml -i patch.diff -o final.xml

但是当它们位于不同的目录中时,我尝试使用以下命令:

补丁 /var/local/documents/document.xml -i /var/local/patches/patch.diff -o /var/local/final/final.xml

我收到以下错误:

(Stripping trailing CRs from patch.)
patching file {file}
Hunk#1 FAILED at 20.
1 out of 1 hunk FAILED -- saving rejects to file {file}

我在某处读到我应该使用 -d 和 -p 来正确处理目录,但我不知道应该如何做...

I'm trying to apply a patch using 2 files in different directories. The output file should be in a different directory too. The first file is in /var/local/documents/document.xml and patch file is located in /var/local/patches/patch.diff and I want the output file should be created in /var/local/final/final.xml.

When the files are located in the same directory, this command works:

patch document.xml -i patch.diff -o final.xml

But when they are in separate directories and I try to use the following command:

patch
/var/local/documents/document.xml -i
/var/local/patches/patch.diff -o
/var/local/final/final.xml

I get the following error:

(Stripping trailing CRs from patch.)
patching file {file}
Hunk#1 FAILED at 20.
1 out of 1 hunk FAILED -- saving rejects to file {file}

I've read somewhere that I should use -d and -p to work correctly with directories but I have no clue how I should do it...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

坐在坟头思考人生 2024-10-14 23:43:09

是的,它是 -p 开关(在您的情况下,它应该从补丁路径中删除 2 个条目):

cd /var/local/documents
patch -p 2 -o ../final/final.xml document.xml < ../patches/patch.diff

Yes, it's -p switch (in your case it should strip 2 entries from patch path):

cd /var/local/documents
patch -p 2 -o ../final/final.xml document.xml < ../patches/patch.diff
止于盛夏 2024-10-14 23:43:09

试试这个:

$ mv /var/local/final/final.xml /var/local/final/document.xml
$ (cd /var/local/final && patch document.xml) < patch.diff
$ mv /var/local/final/document.xml /var/local/final/final.xml

Try this:

$ mv /var/local/final/final.xml /var/local/final/document.xml
$ (cd /var/local/final && patch document.xml) < patch.diff
$ mv /var/local/final/document.xml /var/local/final/final.xml
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文