views:

606

answers:

5

I've got a file and a patch for it. I'd like to visually apply the patch, t.i. see how the changes proposed by the patch look in context, make some corrections, and save the resulting file.

What tool can do that?

Neither of the visual diff tools (i.e. meld, diffuse, diffmerge) do what I want: they don't work with patches, they merely merge whole files.

+1  A: 

You may use the emacs ediff mode. It lets you see and validate each chunk interactively. For what it's worth, I have this handy script in my ~/bin directory:

#!/bin/bash
if [ "$1" == "--text" ] ; then shift; fi
if diff --brief $1 $2 ; then 
exit 0 
else
emacs -fn 8x13bold --eval '(ediff-files "'$1'" "'$2'")'
fi
Pascal Cuoq
A: 

The idea with visual diff tools is that you can:

  1. make a backup copy of the patched file (or a new pristine checkout of the whole tree)
  2. apply the patch
  3. use the visual diff tool to review the changes in context
  4. make any desired change to the patched file within the visual diff tool.

Some tools, such as meld or diffuse will automatically diff against the previous committed version of the files.

The key insight is that you CAN apply the patch, they discard everything you don't like as long as you have a backup copy, or if you are working on a clean checkout.

If you feel more comfortable with reading and modifying unified diffs, and just want to have more context for the diff, emacs has a fairly unique feature, which is next-error-follow-mode while viewing a diff file (diff major mode). That shows the context of a diff line in the target file.

ddaa
+1  A: 

See use vimdiff with a diff file.

gvim original.file +'vert diffpa the.patch'

This will open GVim and split the window, with the original on the left and the patch applied on the right. You can then add, remove, or change hunks, and save the changes. (Well, if you want to create a new.patch you'll have to run diff again, but that's not difficult.)

ephemient
A: 

Does xxdiff do what you are looking for?

hillu
Seem to work with whole files and not a patch as asked for.
Zitrax
A: 

I'd use meld.

Create two copies of the files, one without and another with the patch. Use meld to compare them, and you can see exactly what the patch is changing and make changes as necessary.

Seriously, why is this so hard?

MarkR