When patching what's the difference between arguments -p0 and -p1?

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











up vote
17
down vote

favorite
9












What's the difference between patch -p0 and patch -p1?



Is there any difference at all?










share|improve this question

























    up vote
    17
    down vote

    favorite
    9












    What's the difference between patch -p0 and patch -p1?



    Is there any difference at all?










    share|improve this question























      up vote
      17
      down vote

      favorite
      9









      up vote
      17
      down vote

      favorite
      9






      9





      What's the difference between patch -p0 and patch -p1?



      Is there any difference at all?










      share|improve this question













      What's the difference between patch -p0 and patch -p1?



      Is there any difference at all?







      patch






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 9 '11 at 22:45









      chrisjlee

      2,347123350




      2,347123350




















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          21
          down vote



          accepted










          The most common way to create a patch is to run the diff command or some version control's built-in diff-like command. Sometimes, you're just comparing two files, and you run diff like this:



          diff -u version_by_alice.txt version_by_bob.txt >alice_to_bob.patch


          Then you get a patch that contains changes for one file and doesn't contain a file name at all. When you apply that patch, you need to specify which file you want to apply it to:



          patch <alice_to_bob.patch version2_by_alice.txt


          Often, you're comparing two versions of a whole multi-file project contained in a directory. A typical invocation of diff looks like this:



          diff -ru old_version new_version >some.patch


          Then the patch contains file names, given in header lines like diff -ru old_version/dir/file new_version/dir/file. You need to tell patch to strip the prefix (old_version or new_version) from the file name. That's what -p1 means: strip one level of directory.



          Sometimes, the header lines in the patch contain the file name directly with no lead-up. This is common with version control systems; for example cvs diff produces header lines that look like diff -r1.42 foo. Then there is no prefix to strip, so you must specify -p0.



          In the special case when there are no subdirectories in the trees that you're comparing, no -p option is necessary: patch will discard all the directory part of the file names. But most of the time, you do need either -p0 or -p1, depending on how the patch was produced.






          share|improve this answer



























            up vote
            16
            down vote













            From the man:




            -pnum or --strip=num
            Strip the smallest prefix containing num leading slashes from each
            file name found in the patch file. A sequence of one or more adjacent
            slashes is counted as a single slash. This controls how file
            names found in the patch file are treated, in case you keep your
            files in a different directory than the person who sent out the
            patch.
            For example, supposing the file name in the patch file was:



             /u/howard/src/blurfl/blurfl.c


            setting -p0 gives the entire file name unmodified, -p1 gives



             u/howard/src/blurfl/blurfl.c


            without the leading slash, -p4 gives



             blurfl/blurfl.c






            share|improve this answer



























              up vote
              3
              down vote













              The difference is if when patching, we use what I can call "path trimming" or not.



              Say we have a path /George/W/Bush. Executing a patch on it with the -p0 argument will treat the path as is:



              /George/W/Bush


              But we can trim the path while patching:



              -p1 will remove the root slash (note the start is just George now, without a slash left to it):



              George/W/Bush


              -p2 will remove George (and adjacent right slash):



               W/Bush


              -p3 will remove W (and adjacent right slash):



               Bush


              Why would anyone do this



              It may be done to patch files with similar names in current directory, but I'm not sure. I tend to think it's most convenient to use the full path as with -p0 anyway.






              share|improve this answer






















                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',
                convertImagesToLinks: false,
                noModals: false,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: null,
                bindNavPrevention: true,
                postfix: "",
                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%2f26501%2fwhen-patching-whats-the-difference-between-arguments-p0-and-p1%23new-answer', 'question_page');

                );

                Post as a guest






























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes








                up vote
                21
                down vote



                accepted










                The most common way to create a patch is to run the diff command or some version control's built-in diff-like command. Sometimes, you're just comparing two files, and you run diff like this:



                diff -u version_by_alice.txt version_by_bob.txt >alice_to_bob.patch


                Then you get a patch that contains changes for one file and doesn't contain a file name at all. When you apply that patch, you need to specify which file you want to apply it to:



                patch <alice_to_bob.patch version2_by_alice.txt


                Often, you're comparing two versions of a whole multi-file project contained in a directory. A typical invocation of diff looks like this:



                diff -ru old_version new_version >some.patch


                Then the patch contains file names, given in header lines like diff -ru old_version/dir/file new_version/dir/file. You need to tell patch to strip the prefix (old_version or new_version) from the file name. That's what -p1 means: strip one level of directory.



                Sometimes, the header lines in the patch contain the file name directly with no lead-up. This is common with version control systems; for example cvs diff produces header lines that look like diff -r1.42 foo. Then there is no prefix to strip, so you must specify -p0.



                In the special case when there are no subdirectories in the trees that you're comparing, no -p option is necessary: patch will discard all the directory part of the file names. But most of the time, you do need either -p0 or -p1, depending on how the patch was produced.






                share|improve this answer
























                  up vote
                  21
                  down vote



                  accepted










                  The most common way to create a patch is to run the diff command or some version control's built-in diff-like command. Sometimes, you're just comparing two files, and you run diff like this:



                  diff -u version_by_alice.txt version_by_bob.txt >alice_to_bob.patch


                  Then you get a patch that contains changes for one file and doesn't contain a file name at all. When you apply that patch, you need to specify which file you want to apply it to:



                  patch <alice_to_bob.patch version2_by_alice.txt


                  Often, you're comparing two versions of a whole multi-file project contained in a directory. A typical invocation of diff looks like this:



                  diff -ru old_version new_version >some.patch


                  Then the patch contains file names, given in header lines like diff -ru old_version/dir/file new_version/dir/file. You need to tell patch to strip the prefix (old_version or new_version) from the file name. That's what -p1 means: strip one level of directory.



                  Sometimes, the header lines in the patch contain the file name directly with no lead-up. This is common with version control systems; for example cvs diff produces header lines that look like diff -r1.42 foo. Then there is no prefix to strip, so you must specify -p0.



                  In the special case when there are no subdirectories in the trees that you're comparing, no -p option is necessary: patch will discard all the directory part of the file names. But most of the time, you do need either -p0 or -p1, depending on how the patch was produced.






                  share|improve this answer






















                    up vote
                    21
                    down vote



                    accepted







                    up vote
                    21
                    down vote



                    accepted






                    The most common way to create a patch is to run the diff command or some version control's built-in diff-like command. Sometimes, you're just comparing two files, and you run diff like this:



                    diff -u version_by_alice.txt version_by_bob.txt >alice_to_bob.patch


                    Then you get a patch that contains changes for one file and doesn't contain a file name at all. When you apply that patch, you need to specify which file you want to apply it to:



                    patch <alice_to_bob.patch version2_by_alice.txt


                    Often, you're comparing two versions of a whole multi-file project contained in a directory. A typical invocation of diff looks like this:



                    diff -ru old_version new_version >some.patch


                    Then the patch contains file names, given in header lines like diff -ru old_version/dir/file new_version/dir/file. You need to tell patch to strip the prefix (old_version or new_version) from the file name. That's what -p1 means: strip one level of directory.



                    Sometimes, the header lines in the patch contain the file name directly with no lead-up. This is common with version control systems; for example cvs diff produces header lines that look like diff -r1.42 foo. Then there is no prefix to strip, so you must specify -p0.



                    In the special case when there are no subdirectories in the trees that you're comparing, no -p option is necessary: patch will discard all the directory part of the file names. But most of the time, you do need either -p0 or -p1, depending on how the patch was produced.






                    share|improve this answer












                    The most common way to create a patch is to run the diff command or some version control's built-in diff-like command. Sometimes, you're just comparing two files, and you run diff like this:



                    diff -u version_by_alice.txt version_by_bob.txt >alice_to_bob.patch


                    Then you get a patch that contains changes for one file and doesn't contain a file name at all. When you apply that patch, you need to specify which file you want to apply it to:



                    patch <alice_to_bob.patch version2_by_alice.txt


                    Often, you're comparing two versions of a whole multi-file project contained in a directory. A typical invocation of diff looks like this:



                    diff -ru old_version new_version >some.patch


                    Then the patch contains file names, given in header lines like diff -ru old_version/dir/file new_version/dir/file. You need to tell patch to strip the prefix (old_version or new_version) from the file name. That's what -p1 means: strip one level of directory.



                    Sometimes, the header lines in the patch contain the file name directly with no lead-up. This is common with version control systems; for example cvs diff produces header lines that look like diff -r1.42 foo. Then there is no prefix to strip, so you must specify -p0.



                    In the special case when there are no subdirectories in the trees that you're comparing, no -p option is necessary: patch will discard all the directory part of the file names. But most of the time, you do need either -p0 or -p1, depending on how the patch was produced.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Dec 9 '11 at 23:19









                    Gilles

                    514k12110201549




                    514k12110201549






















                        up vote
                        16
                        down vote













                        From the man:




                        -pnum or --strip=num
                        Strip the smallest prefix containing num leading slashes from each
                        file name found in the patch file. A sequence of one or more adjacent
                        slashes is counted as a single slash. This controls how file
                        names found in the patch file are treated, in case you keep your
                        files in a different directory than the person who sent out the
                        patch.
                        For example, supposing the file name in the patch file was:



                         /u/howard/src/blurfl/blurfl.c


                        setting -p0 gives the entire file name unmodified, -p1 gives



                         u/howard/src/blurfl/blurfl.c


                        without the leading slash, -p4 gives



                         blurfl/blurfl.c






                        share|improve this answer
























                          up vote
                          16
                          down vote













                          From the man:




                          -pnum or --strip=num
                          Strip the smallest prefix containing num leading slashes from each
                          file name found in the patch file. A sequence of one or more adjacent
                          slashes is counted as a single slash. This controls how file
                          names found in the patch file are treated, in case you keep your
                          files in a different directory than the person who sent out the
                          patch.
                          For example, supposing the file name in the patch file was:



                           /u/howard/src/blurfl/blurfl.c


                          setting -p0 gives the entire file name unmodified, -p1 gives



                           u/howard/src/blurfl/blurfl.c


                          without the leading slash, -p4 gives



                           blurfl/blurfl.c






                          share|improve this answer






















                            up vote
                            16
                            down vote










                            up vote
                            16
                            down vote









                            From the man:




                            -pnum or --strip=num
                            Strip the smallest prefix containing num leading slashes from each
                            file name found in the patch file. A sequence of one or more adjacent
                            slashes is counted as a single slash. This controls how file
                            names found in the patch file are treated, in case you keep your
                            files in a different directory than the person who sent out the
                            patch.
                            For example, supposing the file name in the patch file was:



                             /u/howard/src/blurfl/blurfl.c


                            setting -p0 gives the entire file name unmodified, -p1 gives



                             u/howard/src/blurfl/blurfl.c


                            without the leading slash, -p4 gives



                             blurfl/blurfl.c






                            share|improve this answer












                            From the man:




                            -pnum or --strip=num
                            Strip the smallest prefix containing num leading slashes from each
                            file name found in the patch file. A sequence of one or more adjacent
                            slashes is counted as a single slash. This controls how file
                            names found in the patch file are treated, in case you keep your
                            files in a different directory than the person who sent out the
                            patch.
                            For example, supposing the file name in the patch file was:



                             /u/howard/src/blurfl/blurfl.c


                            setting -p0 gives the entire file name unmodified, -p1 gives



                             u/howard/src/blurfl/blurfl.c


                            without the leading slash, -p4 gives



                             blurfl/blurfl.c







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Dec 9 '11 at 23:03









                            Stéphane Gimenez

                            18.9k15074




                            18.9k15074




















                                up vote
                                3
                                down vote













                                The difference is if when patching, we use what I can call "path trimming" or not.



                                Say we have a path /George/W/Bush. Executing a patch on it with the -p0 argument will treat the path as is:



                                /George/W/Bush


                                But we can trim the path while patching:



                                -p1 will remove the root slash (note the start is just George now, without a slash left to it):



                                George/W/Bush


                                -p2 will remove George (and adjacent right slash):



                                 W/Bush


                                -p3 will remove W (and adjacent right slash):



                                 Bush


                                Why would anyone do this



                                It may be done to patch files with similar names in current directory, but I'm not sure. I tend to think it's most convenient to use the full path as with -p0 anyway.






                                share|improve this answer


























                                  up vote
                                  3
                                  down vote













                                  The difference is if when patching, we use what I can call "path trimming" or not.



                                  Say we have a path /George/W/Bush. Executing a patch on it with the -p0 argument will treat the path as is:



                                  /George/W/Bush


                                  But we can trim the path while patching:



                                  -p1 will remove the root slash (note the start is just George now, without a slash left to it):



                                  George/W/Bush


                                  -p2 will remove George (and adjacent right slash):



                                   W/Bush


                                  -p3 will remove W (and adjacent right slash):



                                   Bush


                                  Why would anyone do this



                                  It may be done to patch files with similar names in current directory, but I'm not sure. I tend to think it's most convenient to use the full path as with -p0 anyway.






                                  share|improve this answer
























                                    up vote
                                    3
                                    down vote










                                    up vote
                                    3
                                    down vote









                                    The difference is if when patching, we use what I can call "path trimming" or not.



                                    Say we have a path /George/W/Bush. Executing a patch on it with the -p0 argument will treat the path as is:



                                    /George/W/Bush


                                    But we can trim the path while patching:



                                    -p1 will remove the root slash (note the start is just George now, without a slash left to it):



                                    George/W/Bush


                                    -p2 will remove George (and adjacent right slash):



                                     W/Bush


                                    -p3 will remove W (and adjacent right slash):



                                     Bush


                                    Why would anyone do this



                                    It may be done to patch files with similar names in current directory, but I'm not sure. I tend to think it's most convenient to use the full path as with -p0 anyway.






                                    share|improve this answer














                                    The difference is if when patching, we use what I can call "path trimming" or not.



                                    Say we have a path /George/W/Bush. Executing a patch on it with the -p0 argument will treat the path as is:



                                    /George/W/Bush


                                    But we can trim the path while patching:



                                    -p1 will remove the root slash (note the start is just George now, without a slash left to it):



                                    George/W/Bush


                                    -p2 will remove George (and adjacent right slash):



                                     W/Bush


                                    -p3 will remove W (and adjacent right slash):



                                     Bush


                                    Why would anyone do this



                                    It may be done to patch files with similar names in current directory, but I'm not sure. I tend to think it's most convenient to use the full path as with -p0 anyway.







                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited 12 mins ago

























                                    answered Jul 13 '16 at 12:59









                                    JohnDoea

                                    142728




                                    142728



























                                         

                                        draft saved


                                        draft discarded















































                                         


                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function ()
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f26501%2fwhen-patching-whats-the-difference-between-arguments-p0-and-p1%23new-answer', 'question_page');

                                        );

                                        Post as a guest













































































                                        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?