tags:

views:

101

answers:

2

Is there a way to apply a single hunk from a diff to a file? For example, say I do a diff from file A and B, and that produces three chunks of differences, each denoted with something like...

@@ -971,30 +977,28 @@

...(in the case of unified diffs). I'd then want to be able to feed that diff into stdin, and ask patch to only apply hunk N.

The manual method would be to cut-and-paste the interesting hunks, but I'm not after that kind of a solution.

A: 

Some of the GUI diff/patch tools have a way to select blocks or even individual lines. I know TortoiseDiff from TortoiseSVN can work this way. I think I've seen windiff do it, but it's been a while since I had to use it.

As far as command line tools, I have not seen anything that will do what you are asking.

David Hogue
I couldn't find anything in the man page, but felt that it must exist - and it's just my inability to find it. So - patch itself has no native support for this - is that accurate?
Cyrus
A: 

In my past experience, it's just not very hard to read a context diff into an editor and prune it down. I don't really see the advantage of a complex argument structure for patch over that. Is there something in particular you are trying to do that makes this intractable?

bmargulies
Let's put it this way - if patch *did* support it - I *would* use it. I have some vim macros that remove diff syntax so it's not too bad, but it would be easier to just type a single command.
Cyrus