Permanently reversing a patch-file

Oliver Charlesworth picture Oliver Charlesworth · Oct 11, 2010 · Viewed 18.3k times · Source

Sometimes, for whatever reason, I have to produce patch-files (under Linux) that are in the wrong direction. I know that I can deal with this by using the -R switch when applying it via patch, but it would be nice if there were a way of permanently reversing the patch-file. Is there a utility that can do this, or e.g. a regex that would be guaranteed to work?

UPDATE

Lie Ryan has suggested a neat way of doing this. However, it requires access to the original source file(s). So I suppose I should update my question to state that I'm more after a way of achieving this given only the patch-file itself.

Answer

camh picture camh · Oct 11, 2010

You can use the tool interdiff(1) from patchutils. In particular, the man page for interdiff says:

To reverse a patch, use /dev/null for diff2.

So,

$ interdiff -q file.patch /dev/null > reversed.patch

The -q / --quiet prevents the insertion of reverted: lines.