9

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?

4

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

| improve this answer | |
3

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

| improve this answer | |
  • This worked for me on Ubuntu 16.04. – David Cullen Aug 9 '16 at 15:02
0

Consider using the undocumented --version-control none option. That option is documented for the FreeBSD variant of patch.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.