One Two Three
One Two Three

Reputation: 23497

How do I "inverse" a diff file?

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:

Upvotes: 15

Views: 7185

Answers (3)

caduceus
caduceus

Reputation: 1828

You can leave the diff as is and apply in reverse

git apply --reverse backwards-diff

Upvotes: 12

Tom Hale
Tom Hale

Reputation: 46813

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

interdiff -q my-diff-file /dev/null

Upvotes: 11

Mark Jin
Mark Jin

Reputation: 2903

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

Upvotes: 6

Related Questions