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.
filterdiff might help.
It allows extraction of subset of patches matching a variety of requirements, from one/many patch files. For example, here we extract from the file unified_diff.patch
, the patches applicable to files with name matching one_file.c
, only to lines 950 to 1050 of the original file:
filterdiff -i *one_file.c --lines=950,1050 unified_diff.patch
To extract specific/range of hunks:
filterdiff --hunks=1,3,5-8,15 file.patch
Extracting patches from mail messages:
filterdiff message-with-diff-in-the-body > file.patch
etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With