Dan Nissenbaum
Dan Nissenbaum

Reputation: 13908

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

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:

--- /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.

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.

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, patch presents me with a prompt for each file because it cannot locate it).

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

Upvotes: 3

Views: 11388

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798686

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

Upvotes: 6

Related Questions