I have two files - fileWithMyFix.c and fileCustUpdated.c. I made my fixes to filewithmyfix but was not aware that a customer was updating the same file to make other (unrelated changes).

I need to push my changes into their file. A flat patch doesn't seem to be working, since there are differences in both files. If I diff them and apply that patch, it tries to revert fileCustUpdated.c to match fileWithMyFix, but ends up creating a mess.

Is there a way to pinpoint specific portions of the file to patch? Do I have to diff fileWithMyFix.c against an untouched file fresh off svn, and then apply the patch that way? I figure line numbers won't line up and there will be issues there as well.

Edit - I may have been doing the diff backwards, but I let it do the reversion and it applied the patch correctly. New question - which way do I do the diff to avoid this?


You have to diff your modified file against the unmodified version. If there are different options for the diff output format, create a unified diff or context diff. These formats contain some context lines around the modified lines. The patch tool will normally find the lines to be modified even if the line numbers have changed.

If the file is in SVN you can use two workspaces and commit the customers version in one workspace, then update the workspace that contains your modified version. This should merge the customer's changes into your file, and (after possibly resolving the conflicts) finally you can commit your file. which should now have all modifications in it.

  • Unfortunately I can't do this under version control. The patch tool is detecting a reversed patch when I try to apply, and failing on every hunk with this method. I'm using diff -Naru fileWithMyChanges.c originalSvnFile.c > diffs.c – Brydon Gibson Jan 7 '19 at 16:25
  • 1
    patch is detecting a reversed patch because you asked diff to find the changes from fileWithMyChanges.c to originalSvnFile.c. Did you confirm that it's a reversed patch? If not it's expected that all hunks fail to apply. Try diff -u originalSvnFile.c fileWithMyChanges.c or diff -au... if it thinks your files are binary. Options -N and -r are not necessary in your case but don't hurt. – Bodo Jan 7 '19 at 17:51

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.