10

Since I'm stuck with Subversion and shell tools for the time, git-gui and such are out of the question. Are there any shell tools to apply a patch line-by-line interactively?

Braiam
  • 1
  • 11
  • 47
  • 78
l0b0
  • 55,365
  • 30
  • 138
  • 223

3 Answers3

12

Try passing the --dry-run option to patch. This will let you identify the problem hunks and edit the patch and/or file being patched appropriately.

David Underhill
  • 15,896
  • 7
  • 53
  • 61
ezod
  • 7,261
  • 2
  • 24
  • 34
  • 1
    [`sdiff`](http://netbsd.gw.com/cgi-bin/man-cgi?sdiff++NetBSD-current) is good for merging two files. It will not really help when you have a patch to apply interactively. Well, for that, simply using `patch` with the `--dry-mode` option so find the invalid chunks and edit is probably enough. – tonio Feb 09 '11 at 14:29
  • 2
    @l0b0: it's actually `--dry-run` – Hasturkun Feb 09 '11 at 14:36
  • 7
    `sdiff file1 file2 -o outfile` will diff file1 and file2, and show you interactively each change, and you choose which one you want to go to the outfile. `sdiff` is the best. – pvinis Apr 30 '12 at 19:51
  • 2
    @pvinis: Your comment should be an answer, and IMO it should be the accepted one! – Matthew Leingang Oct 01 '14 at 19:16
4

ipatch brings the power and convenience of selecting and editing patches in Darcs to those who are not using the Darcs version control system.

It allows the user to interactively split a patch file into several patch file, as well as applying a patch interactively and possibly partially.

There's an introduction from the author here.

Community
  • 1
  • 1
ephemient
  • 198,619
  • 38
  • 280
  • 391
0

See this answer.

Although not interactive, another option is to manually edit the .diff file and remove any changes you don't want.

If you open a diff file in emacs and put the editor in diff-mode you can edit patches and emacs will try to update the hunk markers. (Emacs will open .diff files in diff-mode automatically.)

To update markers manually after making changes do C-c C-w to regenerate the hunk.

To apply hunks one by one do C-c C-a. To reverse-apply do C-u C-c C-a. You can also M-x diff-tell-file-name to apply them to a different file.

I found patch original patch.diff to be more reliable than patch < patch.diff and patch files created with diff -u to be easier to work with.

Information also documented here.

UPDATE [5.21.21]:
C-c C-s lets you split up hunks which is very useful for manually editing. Sometimes C-c C-w (diff-ignore-whitespace-hunk) does not do what you intended, so the safest bet is to split the hunks and let emacs update the headers automatically. This is especially useful when keeping lines unchanged; just split into a hunk and delete to remove the change.

young_souvlaki
  • 1,886
  • 4
  • 24
  • 28