13

Say I have a diff file looking basically like the following.

+line a
-line b

Is it possible to do one (or both) of the following:

  • Inverse this file (so I'd get)

    -line a
    +line b
    
  • Pass some argument to patch so the end result the same as applying the inversed diff file described above

Tom Hale
  • 40,825
  • 36
  • 187
  • 242
One Two Three
  • 22,327
  • 24
  • 73
  • 114

3 Answers3

7

You can leave the diff as is and apply in reverse

git apply --reverse backwards-diff
caduceus
  • 1,542
  • 2
  • 16
  • 21
6

To rewrite a reversed / inverted diff file, use interdiff from diffutils:

interdiff -q my-diff-file /dev/null
Tom Hale
  • 40,825
  • 36
  • 187
  • 242
5

Here is what you should do (assuming newFile.txt is the file you want to apply the reversed diff file on and diffFile.txt is the diff file):

patch -R newFile.txt diffFile.txt -o oldFile.txt
Mark Jin
  • 2,616
  • 3
  • 25
  • 37