Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a more flexible alternative to diff/patch?

Tags:

java

diff

patch

I'm trying to maintain a set of patches, which needs to be applied to several versions/branches of the code. The current diff/patch method (and git cherry-picking) is not flexible enough, mainly due to the dependency of the context. For example assume my patch adds a few constants in a java class. If in one version of the code another constant was inserted, exactly at the same place, patch will fail. In a general circumstance this is ok, since the order might be important, however in case of java code the order of the fields (at leaast in 99% of the cases) doesn't matter. In another example I wanted to insert one line right after another one. However the context contains in total 6 lines, and the patch is applied normally only if all of those matches.

I tried to manually edit the diff files, to keeping for example only one line of context, but then patch failed with the message "broken patch".

So I would like to know if there is a better (open source preferably) alternative to diff/patch which is more flexible.

Thank you in advance! /Pal

like image 901
Pal Szasz Avatar asked Feb 22 '26 06:02

Pal Szasz


1 Answers

Try to use git format-patch -U1 <revisions>, it produces a patch with 1 line of context.

like image 162
kan Avatar answered Feb 24 '26 18:02

kan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!