Linux 存在完整路径时,如何使用补丁在不同文件夹上为文件夹应用 diff 文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6702418/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 05:05:55  来源:igfitidea点击:

How to apply a diff file for a folder, using patch, on a different folder when full path is present?

linuxdiffpatch

提问by Dan Nissenbaum

I have downloaded a diff file to modify a number of files within a versioned project directory (Xerces 2.8). The diff file contains the full path for each "left" file (the one represented by the - signs). The "right" file (+ signs) contains a relative path. For example:

我已经下载了一个 diff 文件来修改版本化项目目录 (Xerces 2.8) 中的许多文件。diff 文件包含每个“左”文件(由 - 符号表示的文件)的完整路径。“正确”文件(+ 号)包含一个相对路径。例如:

--- /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_textproc_xercesc/work/xerces-c-src_2_8_0/src/xercesc/util/Platforms/MacOS/MacCarbonFile.cpp  2007-08-28 20:44:07.000000000 +0200
+++ src/xercesc/util/Platforms/MacOS/MacCarbonFile.cpp  2009-10-28 19:37:22.000000000 +0100

My local copy of the project directory that I'd like to update with the diff file is, of course, at a different full path.

我想用 diff 文件更新的项目目录的本地副本当然位于不同的完整路径中。

I cannot figure out where to place the diff file (or rather, in what directory to position myself when I run patch) and what command to run.

我不知道在哪里放置 diff 文件(或者更确切地说,在我运行时将自己定位在哪个目录中patch)以及要运行的命令。

Because the second (+) file is a relative path, I thought that positioning myself in the proper location in my local file system so that the relative path is correct - and then issuing the command

因为第二个 (+) 文件是相对路径,我认为将自己定位在本地文件系统中的正确位置,以便相对路径正确 - 然后发出命令

patch -i patchfile

... would work. It does not (instead, patchpresents me with a prompt for each file because it cannot locate it).

... 会工作。它没有(相反,patch向我显示每个文件的提示,因为它无法找到它)。

What command should I issue to get the diff file to merge using patch?

我应该发出什么命令来合并 diff 文件patch

采纳答案by Ignacio Vazquez-Abrams

Pass -pfollowed by the appropriate number of path prefixes to strip.

传递-p后跟适当数量的路径前缀以进行剥离。