Patch only a portion of a file

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












1















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?










share|improve this question




























    1















    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?










    share|improve this question


























      1












      1








      1








      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?










      share|improve this question
















      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?







      patch version-control






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 7 at 16:53







      Brydon Gibson

















      asked Jan 7 at 14:15









      Brydon GibsonBrydon Gibson

      18618




      18618




















          1 Answer
          1






          active

          oldest

          votes


















          2














          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.






          share|improve this answer























          • 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 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 at 17:51










          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f493002%2fpatch-only-a-portion-of-a-file%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          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.






          share|improve this answer























          • 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 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 at 17:51















          2














          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.






          share|improve this answer























          • 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 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 at 17:51













          2












          2








          2







          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.






          share|improve this answer













          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 7 at 15:39









          BodoBodo

          5186




          5186












          • 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 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 at 17:51

















          • 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 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 at 17:51
















          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 at 16:25





          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 at 16:25




          1




          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 at 17:51





          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 at 17:51

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Unix & Linux Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f493002%2fpatch-only-a-portion-of-a-file%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown






          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Displaying single band from multi-band raster using QGIS

          How many registers does an x86_64 CPU actually have?