1

I'm trying to generate patches for a bunch of files I changed. I'm using Meld which does a great job of diff’ing the files in a nice visual manor, then it allows me to save and generate a patch file based on those changes.

The problem I have is that it's slow to do this one at a time. Is there a similar tool that I can use for batch work? I want it to recursively check all the files in two directories and generate all the patch files based on its findings.

2 Answers 2

3

Although I've never used Meld, I have a feeling it's actually using 'diff' under the covers. The way I've always generated patch files is simple:

$ diff -ruN ${dir1} ${dir2} > ${patchfile}.patch

That generates a single large patch file, which you can then break up as apporpriate. To generate individual patch files for each change found, you would simply run that large file through a script that split when it saw a new changeset (a script I don't have handy or know of, since I've never used one like it).

2
  • I think you're right, I was not aware of the -u option for diff, that does make the formatting the same. How would I update that line to avoid certain files? For example any *.o files that are in the directories.
    – Mike
    Dec 5, 2012 at 14:33
  • Use an --exclude={pattern} option. There are a number of options you may or may not want to use, I'd suggest reading through the man page to understand what's available. The diff program is actually quite powerful.
    – John
    Dec 5, 2012 at 14:37
1

That's what diff is for. patch takes diff output files as input. Just run diff in a BASH loop for each of your files. For example, if the original files are in dirA and the new ones in dirB (with the same filenames), do this (in ./dirA):

for n in $(ls * | grep -v ".o$"); do \
    diff -uN $n dirB/$n > $n.patch; patch $n < $n.patch; \
done 
1
  • @Mike, see my updated answer for avoiding .o files.
    – terdon
    Dec 5, 2012 at 14:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .