How to prevent patch from creating backup files?

I'm writing some code that will apply the patch(1) program, and I want to completely prevent it from creating backup files. That is, I don't want it to create foo.orig files when it either fails to update a particular file (in which case it creates a foo.rej file), or when it successfully updates a file but there's some fuzziness involved, both of which it ordinarily does. This seems to be easier said than done.

Base case: I run "patch" against a Debian source directory, and it fails to update the debian/changelog file. patch creates a file debian/changelog.orig file (which is what I'm trying to avoid).

The documentation mentions a --no-backup-if-mismatch switch, which seems to be just what I need. But when I add it, the backup file is still created, only now it's called debian/changelog.~1~.

The documentation also says that when the --posix switch is present, backups will not be made. When I use this switch in place of --no-backup-if-mismatch, the backup file is still created, but with the original .orig suffix.

The only workaround I've found is to use the -B/--prefix switch to direct backups to be written to a directory of my choice. But this seems like an ugly hack. Isn't there a cleaner way to prevent backups?


Apparently -B/--prefix is the only way to go.


According to (diffutils)Backups, --no-backup-if-mismatch does what you want.