patch.html 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <style type="text/css">
  7. @import url('../css/main.css');
  8. </style>
  9. <title>
  10. Libreboot documentation: using diff and patch
  11. </title>
  12. </head>
  13. <body>
  14. <div class="section">
  15. <h1 id="pagetop">Diff and patch</h1>
  16. <p>This is just a quick guide for reference, use 'man' to know more.</p>
  17. <p>
  18. <a href="index.html">Back to index</a>
  19. </p>
  20. </div>
  21. <div class="section">
  22. <h1>
  23. Apply a patch
  24. </h1>
  25. <p class="important">
  26. To apply a patch to a single file, do that in it's directory:<br/>
  27. <b>$ patch &lt; foo.patch</b>
  28. </p>
  29. <p>
  30. Assuming that the patch is distributed in unified format identifying
  31. the file the patch should be applied to, the above will work. Otherwise:<br/>
  32. <b>$ patch foo.txt &lt; bar.patch</b>
  33. </p>
  34. <p>
  35. You can apply a patch to an entire directory, but note the &quot;p level&quot;.
  36. What this means is that inside patch files will be the files that you
  37. intend to patch, identified by path names that might be different
  38. when the files ane located on your own computer instead of on the computer
  39. where the patch was created. 'p' level instructs the 'patch' utility to
  40. ignore parts of the path name to identify the files correctly. Usually a
  41. p level of 1 will work, so you would use:<br/>
  42. <b>$ patch -p1 &lt; baz.patch</b>
  43. </p>
  44. <p>
  45. Change to the top level directory before running this. If a patch level
  46. of 1 cannot identify the files to patch, then inspect the patch file for file names.
  47. For example:<br/>
  48. <b>/home/user/do/not/panic/yet.c</b>
  49. </p>
  50. <p>
  51. and you are working in a directory that contains panic/yet.c, use:<br/>
  52. <b>$ patch -p5 &lt; baz.patch</b>
  53. </p>
  54. <p>
  55. You usually count one up for each path separator (forward slash)
  56. removed from the beginning of the path, until you are left with a path
  57. that exists in the current working directory. The count is the p level.
  58. </p>
  59. <p>
  60. Removing a patch using the -R flag<br/>
  61. <b>$ patch -p5 -R &lt; baz.patch</b>
  62. </p>
  63. <p><a href="#pagetop">Back to top of page.</a></p>
  64. </div>
  65. <div class="section">
  66. <h1>
  67. Create a patch with diff
  68. </h1>
  69. <p>
  70. Diff can create a patch for a single file:<br/>
  71. <b>$ diff -u original.c new.c &gt; original.patch</b>
  72. </p>
  73. <p>
  74. For diff'ing a source tree:<br/>
  75. <b>$ cp -R original new</b>
  76. </p>
  77. <p>
  78. Do whatever you want in new/ and then diff it:<br/>
  79. <b>$ diff -rupN original/ new/ &gt; original.patch</b>
  80. </p>
  81. <p><a href="#pagetop">Back to top of page.</a></p>
  82. </div>
  83. <div class="section">
  84. <h1>
  85. git diff
  86. </h1>
  87. <p>
  88. git is something special.
  89. </p>
  90. <p>
  91. Note: this won't show new files created.
  92. </p>
  93. <p>
  94. Just make whatever changes you want to a git clone and then:<br/>
  95. <b>$ git diff &gt; patch.git</b>
  96. </p>
  97. <p>
  98. Note the git revision that you did this with:<br/>
  99. <b>$ git log</b>
  100. </p>
  101. <p>
  102. Alternatively (better yet), commit your changes and then use:<br/>
  103. $ <b>git format-patch -N</b><br/>
  104. Replace N with the number of commits that you want to show.
  105. </p>
  106. <p><a href="#pagetop">Back to top of page.</a></p>
  107. </div>
  108. <div class="section">
  109. <h1>
  110. git apply
  111. </h1>
  112. <p>it really is.</p>
  113. <p>
  114. Now to apply that patch in the future, just git clone it again and do
  115. with the git revision you found from above:<br/>
  116. <b>$ git reset --hard REVISIONNUMBER</b>
  117. </p>
  118. <p>
  119. Now put patch.git in the git clone directory and do:<br/>
  120. <b>$ git apply patch.git</b>
  121. </p>
  122. <p>
  123. If you use a patch from git format-patch, then use <b>git am patch.git</b> instead of <b>git apply patch.git</b>. git-am
  124. will re-create the commits aswell, instead of just applying the patch.
  125. </p>
  126. <p><a href="#pagetop">Back to top of page.</a></p>
  127. </div>
  128. <div class="section">
  129. <p>
  130. Copyright &copy; 2014, 2015 Francis Rowe &lt;info@gluglug.org.uk&gt;<br/>
  131. Permission is granted to copy, distribute and/or modify this document
  132. under the terms of the GNU Free Documentation License, Version 1.3
  133. or any later version published by the Free Software Foundation;
  134. with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
  135. A copy of the license can be found at <a href="../gfdl-1.3.txt">../gfdl-1.3.txt</a>
  136. </p>
  137. <p>
  138. Updated versions of the license (when available) can be found at
  139. <a href="https://www.gnu.org/licenses/licenses.html">https://www.gnu.org/licenses/licenses.html</a>
  140. </p>
  141. <p>
  142. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
  143. EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
  144. AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
  145. ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
  146. IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
  147. WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
  148. PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
  149. ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
  150. KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
  151. ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
  152. </p>
  153. <p>
  154. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
  155. TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
  156. NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
  157. INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
  158. COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
  159. USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
  160. ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
  161. DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
  162. IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
  163. </p>
  164. <p>
  165. The disclaimer of warranties and limitation of liability provided
  166. above shall be interpreted in a manner that, to the extent
  167. possible, most closely approximates an absolute disclaimer and
  168. waiver of all liability.
  169. </p>
  170. </div>
  171. </body>
  172. </html>