3

I have 3 files.

  1. f1.java
  2. f1rev1.java
  3. f1rev2.java

What I want to do is get the diff between "f1.java" and "f1rev1.java" and apply that diff to "f1rev2.java" without considering the diff between f1.java and f1rev2.java.

Is there any tool or libraries that I can use to achieve this? Any language would be fine.

Note - I studies about diff3 algorithm. There it compares both f1.java with f1rev1.java and f1.java with f1rev2.java

I don't want to consider about the diff between f1 and f1rev2.

Ben
  • 51,770
  • 36
  • 127
  • 149

1 Answers1

2

You did not specify your platform (Hint: use an appropriate tag!).

On UNIX-based platforms, you can use the tools diff and patch to achieve what you want to do.

  1. Use diff -u f1.java f1rev1.java > rev1.patch to create a patch
  2. Apply the patch via patch f1rev2.java rev1.patch to the other source file

As you can see, it is easy as cake. Only the differences contained in the patch will be played on the other file. Note that this only works if the patch is compatible with it. You can read the patch file with less to see the changes to be applied.

On a Windows system, you can do the same procedure as outlined here:

How do I apply a diff patch on Windows?

Sadly, but as expected, it is much more time-consuming. Consider the use of MinGW: Apply a patch file in Windows using Mingw or Cygwin.

Community
  • 1
  • 1
ypnos
  • 50,202
  • 14
  • 95
  • 141