[Ilugc] .a-tip-a-day (patch - apply diffs and act as inverse of diff)

  • From: steve@xxxxxxxxxxxx (steve)
  • Date: Wed Sep 30 10:39:16 2009

Hi,

Just a couple of points worth mentioning ...
On 09/30/2009 05:24 AM, Girish Venkatachalam wrote:

Yesterday we saw diff in somewhat detail.

http://ae.iitm.ac.in/pipermail/ilugc/2009-September/051658.html

Today we are going to see the most important tool that every hacker should 
know:
[...snip...]
Anyway remember these things with patch.

          o patch needs a p0 or p1 argument, typically it is only one
of these two - try to find out
             when to use what switch
To do this (in fact in general, it is always be a good idea) to use the 
"--dry-run" switch. According to the man page:
        --dry-run
           Print the results of applying the patches without actually changing 
any files.

Another userful switch is the -b or -B switches - Make backup file of the files 
being patched. See the man page for more info.

          o patch always needs the '<' operator. Without that patch
will never do its job

Umm. That is incorrect. patch reads from stdin. So, you can also send the 
output 
of a pipe to patch. For instance in the days before git, the quick way to 
update 
your kernel sources if you already had an old version of the sources was to get 
only the patchset and apply them. Something like ...

$ cd /usr/src/patches
$ wget -O- ftp://www.kernel.org/<url>/patch-<version>.bz2 | bunzip2 - | patch 
-p1

Once again it shows Larry's complex thought process. Isn't it obvious
that I will only give
a patchfile as argument to patch? Why should I redirect?

...so, you can also send multiple patchfiles to patch ...

$ cat somefile[1234].diff | patch -p1

...and patch will do the right thing !

cheers,
- steve

-- 
random non tech spiel: http://lonetwin.blogspot.com/
tech randomness: http://lonehacks.blogspot.com/
what i'm stumbling into: http://lonetwin.stumbleupon.com/

Other related posts: