patch.html 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. This document is released under the Creative Commons Attribution-ShareAlike 4.0 International Public License and all future versions.
  132. A copy of the license can be found at <a href="../cc-by-sa-4.txt">../cc-by-sa-4.txt</a>.
  133. </p>
  134. <p>
  135. This document is distributed in the hope that it will be useful,
  136. but WITHOUT ANY WARRANTY; without even the implied warranty of
  137. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See <a href="../cc-by-sa-4.txt">../cc-by-sa-4.txt</a> for more information.
  138. </p>
  139. </div>
  140. </body>
  141. </html>