diff and patch tool

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.

Mike

Posted 2012-12-05T14:08:22.533

Reputation: 849

Answers

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).

John

Posted 2012-12-05T14:08:22.533

Reputation: 1 383

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 – 2012-12-05T14:33:34.110

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 – 2012-12-05T14:37:18.460

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 

terdon

Posted 2012-12-05T14:08:22.533

Reputation: 45 216

@Mike, see my updated answer for avoiding .o files. – terdon – 2012-12-05T14:42:57.697