Generating a patch of changes to one file

cp file file.orig
edit file
diff -u file.orig file | tee file.patch

Generating a patch of all changes in a directory

diff -ruN dir.orig dir.mod > all-changes-in-dir.patch

Applying a patch to a file

patch file < file.patch

Applying a patch to a directory

cd dir
patch -p1 < /tmp/all-changes-in-dir.patch

Reversing that patch out again when it doesn't work

cd dir
patch -Rp1 < /tmp/all-changes-in-dir.patch

There are some handy cvs diff commands:

  1. cvs diff -u file # changes since last commit
  2. cvs diff -r1.1 -r1.2 -u file # changes between given revisions

and with git:

  1. git diff -u file # changes since last commit
  2. git diff -u rel22 master file # changes between given branches

This can also give a crude way to reverse a change: use diff to make a patch file and then feed it to patch -R… but there are usually better ways. cvs update's merge options and git revert.

If you are using patch files without revision control much, you may find wiggle helpful: http://cgi.cse.unsw.edu.au/%7Eneilb/source/wiggle/

 
en/development/diff_patch.txt · Last modified: 2007/03/22 04:01 by tipaul
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki