开发者

A visual patch tool for Linux

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开发者_Python百科 whole files.


I really like Kompare. It is just a (very nice) graphical interface for diff.

http://www.caffeinated.me.uk/kompare/

sudo apt-get install kompare

Creating and applying patches

Kompare is able to create a patch file which lists only the differences between two compared text files A and B. Further, Kompare can apply a patch file which was created this way to an original file A and, in this manner, recompute the contents of the corresponding file B. This is a comfortable utility for passing a corrected version of a file to a friend who already has an older version of the same file, because only the (relatively small) patch file has to be delivered and the receiver can generate the corrected file by applying the patch to the original file.

The patches created and applied by Kompare are compatible to patch files generated or applied by the command line interface diff utility, because Kompare is in fact merely a graphical front end to diff and the patches are created and applied by patch, which gets called by Kompare.


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


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


Another option: if you use Eclipse, you can generate and apply patches visually.


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.


On platforms where Kompare (a fairly nice piece of software if KDE is your cup of tea), I agree that Eclipse is a great option.

I have consistently been a reluctant Eclipse user AND I am consistently impressed by how well the tools work (once the platform finally starts up).

On Fedora, I've got just about every front end installed for each of the main version control engines (SVN - also serving my Windows machines, Mercurial, git, etc.); Meld is quite nice (no patch interface though). Submerge works well also. But since Eclipse does know how to apply patches and Working Copy project created itself once I figured out to create the project in the folder containing my working copy, it may become my favorite SVN front end.


I normally use GitExtensions (.NET and Mono) which also supports applying patches interactively. I hope you are already familiar with git.

Edit: Everything mentioned below this line doesn't seem to be available directly in KDiff3. And as I mentioned before: I haven't tried it yet.

GitExtension normally uses KDiff3 as diff tool, which is able to view patches.

http://kdiff3.sourceforge.net/doc/kpart.html

Using it for patches it has only a two window view, (edit) and doesn't support merging :( but it also supports 3 way diff on complete folders etc.

Actually I never tryed it with patches.


Does xxdiff do what you are looking for?


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜