Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I "inverse" a diff file?

Tags:

diff

patch

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

like image 674
One Two Three Avatar asked Feb 11 '16 19:02

One Two Three


3 Answers

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
like image 194
Zhongjun 'Mark' Jin Avatar answered Oct 27 '22 20:10

Zhongjun 'Mark' Jin


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

interdiff -q my-diff-file /dev/null
like image 26
Tom Hale Avatar answered Oct 27 '22 20:10

Tom Hale


You can leave the diff as is and apply in reverse

git apply --reverse backwards-diff
like image 22
caduceus Avatar answered Oct 27 '22 20:10

caduceus