You are not logged in.
Pages: 1
hello guys!
what is the 'right' way to use diff and patch?
i just want the standard simple commands for it,
arch + gentoo + initng + python = enlisy
Offline
I use unified diffs for patch (-u). Whenever I diff something I do "diff -uNr". This will do a unified diff, and recursively (over all files). The N flag will also add new files into the diff (i.e. the whole file will be listed with +++).
When patching, use -u for unified (-n for normal diffs). The most important flag, however, is -p. -p will strip off components in the filename, which is important with recursive diffs.
So, let's take some example "src/" directory. We'll copy it to "src-old/" and then make modifications inside src/.
When we're done:
$ diff -uNr src-old/ src/ > src.patch
rm -rf src/
mv src-old/ src/
cd src/
patch -up1 ../src.patch
The patch file will contain listings like "diff -uNr src-old/myfile.c src/myfile.c" - when you try to patch this, it looks for those dirs (which won't work, because src-old doesn't exist). So, with -p1 (strip 1 off filename), it converts it to "diff -uNr myfile.c myfile.c" and it patches correctly.
Offline
hey thanks phrak,
that's what i call an explanation!
if i get in trouble again i know where to ask, but this stuff works just as i wanted,
arch + gentoo + initng + python = enlisy
Offline
I just do
diff file file2 > file.diff
patch <file.diff
or something like that...
Offline
I just do
diff file file2 > file.diff
patch <file.diffor something like that...
unified diffs are easier to read, and give you the ability for a "fuzz" factor (i.e. it uses more than just line numbers). The other nice thing about unified diffs is that everything above the ---/+++ lines at the top is ignored. Which is why people will send an email and just put the unified diff at the bottom, because with mutt or something similar, you can just pipe the whole email to patch.
$ diff -u hexout.old hexout.cpp
--- hexout.old Mon Sep 26 11:04:22 2005
+++ hexout.cpp Mon Sep 26 11:03:22 2005
@@ -9,6 +9,8 @@
int len = 0;
for(int i = 0; i < 8; ++i)
{
+ len <<= 4;
+ char c = hdr[13+i];
cout << "c=" << c << endl;
if(c >= '0' && c <= '9') len += (c-'0');
else if(c >= 'A' && c <= 'F') len += (c+10-'A');
$ diff hexout.old hexout.cpp
11a12,13
> len <<= 4;
> char c = hdr[13+i];
Offline
Hmm, I've recently submitted a couple of patches for KDE (yay me) and I used Kompare to generate those. The default command used by Kompare is
diff -U 3 -dHrN -- new_file orig_file
I got a quite readable patch using this method.
Some PKGBUILDs: http://members.lycos.co.uk/sweiss3
Offline
I use unified diffs for patch (-u). Whenever I diff something I do "diff -uNr". This will do a unified diff, and recursively (over all files). The N flag will also add new files into the diff (i.e. the whole file will be listed with +++).
When patching, use -u for unified (-n for normal diffs). The most important flag, however, is -p. -p will strip off components in the filename, which is important with recursive diffs.So, let's take some example "src/" directory. We'll copy it to "src-old/" and then make modifications inside src/.
When we're done:$ diff -uNr src-old/ src/ > src.patch rm -rf src/ mv src-old/ src/ cd src/ patch -up1 ../src.patch
The patch file will contain listings like "diff -uNr src-old/myfile.c src/myfile.c" - when you try to patch this, it looks for those dirs (which won't work, because src-old doesn't exist). So, with -p1 (strip 1 off filename), it converts it to "diff -uNr myfile.c myfile.c" and it patches correctly.
I tried doing that, when I apply the patch it just hangs, nada. Any ideas spring to mind as to why this would be happening?
Offline
$ diff -uNr src-old/ src/ > src.patch rm -rf src/ mv src-old/ src/ cd src/ patch -up1 ../src.patch
I tried doing that, when I apply the patch it just hangs, nada. Any ideas spring to mind as to why this would be happening?
I'm no patch boffin, but I believe that call to patch in the above code is missing a redirection. To apply a patch, you redirect the contents of the file into patch:
patch < patch_file
Offline
Cam wrote:$ diff -uNr src-old/ src/ > src.patch rm -rf src/ mv src-old/ src/ cd src/ patch -up1 ../src.patch
I tried doing that, when I apply the patch it just hangs, nada. Any ideas spring to mind as to why this would be happening?
I'm no patch boffin, but I believe that call to patch in the above code is missing a redirection. To apply a patch, you redirect the contents of the file into patch:
patch < patch_file
Actually, I think you're quite right, I never thought of that! You can also use the -i flag to pass it a file I'm pretty sure
Offline
I always use this howto:
http://www.kegel.com/academy/opensource.html
I have to look up the command every time, can never remember it.
Dusty
Offline
Pages: 1