Howdy,
I have a diff file in my /var/tmp and would like to apply patch to a file in a different directory (other than /va/tmp). I tried using patch with -d switch, but that doesn't work. It complains abt 'patch: **** Can't open patch file tilda.diff : No such file or directory'. Do I need to copy my diff file to the directory where original file resides? Or is there any other way round?
- CS.
Hi,
On Thu, Sep 10, 2009 at 14:04, Carlos Santana neubyr@gmail.com wrote:
I have a diff file in my /var/tmp and would like to apply patch to a file in a different directory (other than /va/tmp). I tried using patch with -d switch, but that doesn't work. It complains abt 'patch: **** Can't open patch file tilda.diff : No such file or directory'. Do I need to copy my diff file to the directory where original file resides? Or is there any other way round?
Try:
cd /path/to/file/to/be/patched patch -p0 </var/tmp/tilda.diff
You might want to use -p1 or -p2 or -p3... depending on what is the path to the file inside the .diff file. To figure that out, open the .diff file and look at the lines that start with --- and +++, then see how many directories are there before the filename, use that number for the argument to -p.
HTH, Filipe
Thanks Filipe.
I can do it by cd-ing into file-to-be-patched dir. I think the -d switch in patch command does similar thing (cd). But then it assumes diff file also to be present in that new directory.
I guess the problem is not having full dir path in the diff file itself. The diff file mentions only file name. How do I get full path in my diff file? Any clues?
- CS.
On Thu, Sep 10, 2009 at 1:12 PM, Filipe Brandenburger filbranden@gmail.com wrote:
Hi,
On Thu, Sep 10, 2009 at 14:04, Carlos Santana neubyr@gmail.com wrote:
I have a diff file in my /var/tmp and would like to apply patch to a file in a different directory (other than /va/tmp). I tried using patch with -d switch, but that doesn't work. It complains abt 'patch: **** Can't open patch file tilda.diff : No such file or directory'. Do I need to copy my diff file to the directory where original file resides? Or is there any other way round?
Try:
cd /path/to/file/to/be/patched patch -p0 </var/tmp/tilda.diff
You might want to use -p1 or -p2 or -p3... depending on what is the path to the file inside the .diff file. To figure that out, open the .diff file and look at the lines that start with --- and +++, then see how many directories are there before the filename, use that number for the argument to -p.
HTH, Filipe _______________________________________________ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
Carlos Santana wrote:
Thanks Filipe.
I can do it by cd-ing into file-to-be-patched dir. I think the -d switch in patch command does similar thing (cd). But then it assumes diff file also to be present in that new directory.
I guess the problem is not having full dir path in the diff file itself. The diff file mentions only file name. How do I get full path in my diff file? Any clues?
Could another option be to pipe the diff into patch via STDIN ?
cat /path/to/filename.diff | patch -p0
or something.
nate
Hi,
On Thu, Sep 10, 2009 at 14:34, nate centos@linuxpowered.net wrote:
Could another option be to pipe the diff into patch via STDIN ?
cat /path/to/filename.diff | patch -p0
That's exactly the same as:
$ patch -p0 </path/to/filename.diff
Filipe
Hi,
On Thu, Sep 10, 2009 at 14:28, Carlos Santana neubyr@gmail.com wrote:
Thanks Filipe.
I can do it by cd-ing into file-to-be-patched dir.
So, this means it's fixed for you?
I think the -d switch in patch command does similar thing (cd). But then it assumes diff file also to be present in that new directory.
Yes, it will change directory before looking for the patch file, so I believe you should use absolute pathnames or redirections.
I guess the problem is not having full dir path in the diff file itself. The diff file mentions only file name. How do I get full path in my diff file? Any clues?
I believe the "problem" is that you are not using "patch" as you are supposed to use it...
Read the first lines of "man patch", it will say: "but usually just: patch -pnum <patchfile"
That is how it's intended to be used in most cases. You cd to the directory where the source tree is, then call "patch" using redirection to get the patch file from stdin.
Does using "patch" in that solve your problem? Otherwise, please state clearly what you are trying to achieve.
HTH, Filipe
On Thu, Sep 10, 2009 at 2:55 PM, Filipe Brandenburger filbranden@gmail.com wrote:
Hi,
On Thu, Sep 10, 2009 at 14:28, Carlos Santana neubyr@gmail.com wrote:
Thanks Filipe.
I can do it by cd-ing into file-to-be-patched dir.
So, this means it's fixed for you?
I think the -d switch in patch command does similar thing (cd). But then it assumes diff file also to be present in that new directory.
Yes, it will change directory before looking for the patch file, so I believe you should use absolute pathnames or redirections.
I guess the problem is not having full dir path in the diff file itself. The diff file mentions only file name. How do I get full path in my diff file? Any clues?
I believe the "problem" is that you are not using "patch" as you are supposed to use it...
Read the first lines of "man patch", it will say: "but usually just: patch -pnum <patchfile"
That is how it's intended to be used in most cases. You cd to the directory where the source tree is, then call "patch" using redirection to get the patch file from stdin.
That's helpful. Thanks for the details Filipe.
I need to CD into the to-be-patched-source dir and then patch works. This is because the context diff file is not having absolute path to the to-be-patched file.
If I manually edit first line of context diff starting with *** to provide absolute path, everything works fine.
Is there any way to get absolute path in the diff o/p?
Does using "patch" in that solve your problem? Otherwise, please state clearly what you are trying to achieve.
HTH, Filipe _______________________________________________ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
Hi,
On Thu, Sep 10, 2009 at 17:30, Carlos Santana neubyr@gmail.com wrote:
Is there any way to get absolute path in the diff o/p?
Well, yes, if you run "diff" passing absolute pathnames then (I believe) it will create a path with absolute pathnames... (It might not, considering that this is not very useful. GNU tar is an example of utility which transforms absolute into relative paths since relative is more useful than relative, although I don't believe diff does the same, the same logic would apply to it as well.)
However, I don't really see the usefulness of that since that would restrict you to patching on the same absolute path where you created the diff...
The purpose of "patch" is for others to be able to apply the same changes to their codebases, which can be located anywhere in the directory tree and not necessarily in the same path where you did it.
What exactly is the big problem of changing directories before you apply the patch?
HTH, Filipe
Hi
Carlos Santana neubyr@gmail.com schrieb am 10.09.2009 20:04:02:
Howdy,
I have a diff file in my /var/tmp and would like to apply patch to a file in a different directory (other than /va/tmp). I tried using patch with -d switch, but that doesn't work. It complains abt 'patch: **** Can't open patch file tilda.diff : No such file or directory'. Do I need to copy my diff file to the directory where original file resides? Or is there any other way round?
The exact command you executed would've been nice. -d should work and so it does for me (though this particular usecase is on an OpenBSD box). If you haven't already tried it do the following from anywhere on your system:
patch -d /other/dir -i /var/tmp/tilda.diff -p0
I'm not sure if the order of the options matters, so you might have to consult patch(1).
Please test the above patch command and report back as I'd say it is a bug if it doesn't work. If it didn't work please also post the full patch command and the output of head -5 /var/tmp/tilda.diff
Frank.