logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

git-apply.1 (14313B)


  1. '\" t
  2. .\" Title: git-apply
  3. .\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
  4. .\" Generator: DocBook XSL Stylesheets v1.79.2 <http://docbook.sf.net/>
  5. .\" Date: 2025-03-14
  6. .\" Manual: Git Manual
  7. .\" Source: Git 2.49.0
  8. .\" Language: English
  9. .\"
  10. .TH "GIT\-APPLY" "1" "2025-03-14" "Git 2\&.49\&.0" "Git Manual"
  11. .\" -----------------------------------------------------------------
  12. .\" * Define some portability stuff
  13. .\" -----------------------------------------------------------------
  14. .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  15. .\" http://bugs.debian.org/507673
  16. .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
  17. .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  18. .ie \n(.g .ds Aq \(aq
  19. .el .ds Aq '
  20. .\" -----------------------------------------------------------------
  21. .\" * set default formatting
  22. .\" -----------------------------------------------------------------
  23. .\" disable hyphenation
  24. .nh
  25. .\" disable justification (adjust text to left margin only)
  26. .ad l
  27. .\" -----------------------------------------------------------------
  28. .\" * MAIN CONTENT STARTS HERE *
  29. .\" -----------------------------------------------------------------
  30. .SH "NAME"
  31. git-apply \- Apply a patch to files and/or to the index
  32. .SH "SYNOPSIS"
  33. .sp
  34. .nf
  35. \fIgit apply\fR [\-\-stat] [\-\-numstat] [\-\-summary] [\-\-check]
  36. [\-\-index | \-\-intent\-to\-add] [\-\-3way] [\-\-ours | \-\-theirs | \-\-union]
  37. [\-\-apply] [\-\-no\-add] [\-\-build\-fake\-ancestor=<file>] [\-R | \-\-reverse]
  38. [\-\-allow\-binary\-replacement | \-\-binary] [\-\-reject] [\-z]
  39. [\-p<n>] [\-C<n>] [\-\-inaccurate\-eof] [\-\-recount] [\-\-cached]
  40. [\-\-ignore\-space\-change | \-\-ignore\-whitespace]
  41. [\-\-whitespace=(nowarn|warn|fix|error|error\-all)]
  42. [\-\-exclude=<path>] [\-\-include=<path>] [\-\-directory=<root>]
  43. [\-\-verbose | \-\-quiet] [\-\-unsafe\-paths] [\-\-allow\-empty] [<patch>\&...\:]
  44. .fi
  45. .SH "DESCRIPTION"
  46. .sp
  47. Reads the supplied diff output (i\&.e\&. "a patch") and applies it to files\&. When running from a subdirectory in a repository, patched paths outside the directory are ignored\&. With the \fB\-\-index\fR option, the patch is also applied to the index, and with the \fB\-\-cached\fR option, the patch is only applied to the index\&. Without these options, the command applies the patch only to files, and does not require them to be in a Git repository\&.
  48. .sp
  49. This command applies the patch but does not create a commit\&. Use \fBgit-am\fR(1) to create commits from patches generated by \fBgit-format-patch\fR(1) and/or received by email\&.
  50. .SH "OPTIONS"
  51. .PP
  52. <patch>\&...\:
  53. .RS 4
  54. The files to read the patch from\&.
  55. \fI\-\fR
  56. can be used to read from the standard input\&.
  57. .RE
  58. .PP
  59. \-\-stat
  60. .RS 4
  61. Instead of applying the patch, output diffstat for the input\&. Turns off "apply"\&.
  62. .RE
  63. .PP
  64. \-\-numstat
  65. .RS 4
  66. Similar to
  67. \fB\-\-stat\fR, but shows the number of added and deleted lines in decimal notation and the pathname without abbreviation, to make it more machine friendly\&. For binary files, outputs two
  68. \fB\-\fR
  69. instead of saying
  70. \fB0\fR
  71. \fB0\fR\&. Turns off "apply"\&.
  72. .RE
  73. .PP
  74. \-\-summary
  75. .RS 4
  76. Instead of applying the patch, output a condensed summary of information obtained from git diff extended headers, such as creations, renames, and mode changes\&. Turns off "apply"\&.
  77. .RE
  78. .PP
  79. \-\-check
  80. .RS 4
  81. Instead of applying the patch, see if the patch is applicable to the current working tree and/or the index file and detects errors\&. Turns off "apply"\&.
  82. .RE
  83. .PP
  84. \-\-index
  85. .RS 4
  86. Apply the patch to both the index and the working tree (or merely check that it would apply cleanly to both if
  87. \fB\-\-check\fR
  88. is in effect)\&. Note that
  89. \fB\-\-index\fR
  90. expects index entries and working tree copies for relevant paths to be identical (their contents and metadata such as file mode must match), and will raise an error if they are not, even if the patch would apply cleanly to both the index and the working tree in isolation\&.
  91. .RE
  92. .PP
  93. \-\-cached
  94. .RS 4
  95. Apply the patch to just the index, without touching the working tree\&. If
  96. \fB\-\-check\fR
  97. is in effect, merely check that it would apply cleanly to the index entry\&.
  98. .RE
  99. .PP
  100. \-\-intent\-to\-add
  101. .RS 4
  102. When applying the patch only to the working tree, mark new files to be added to the index later (see
  103. \fB\-\-intent\-to\-add\fR
  104. option in
  105. \fBgit-add\fR(1))\&. This option is ignored unless running in a Git repository and
  106. \fB\-\-index\fR
  107. is not specified\&. Note that
  108. \fB\-\-index\fR
  109. could be implied by other options such as
  110. \fB\-\-cached\fR
  111. or
  112. \fB\-\-3way\fR\&.
  113. .RE
  114. .PP
  115. \-3, \-\-3way
  116. .RS 4
  117. Attempt 3\-way merge if the patch records the identity of blobs it is supposed to apply to and we have those blobs available locally, possibly leaving the conflict markers in the files in the working tree for the user to resolve\&. This option implies the
  118. \fB\-\-index\fR
  119. option unless the
  120. \fB\-\-cached\fR
  121. option is used, and is incompatible with the
  122. \fB\-\-reject\fR
  123. option\&. When used with the
  124. \fB\-\-cached\fR
  125. option, any conflicts are left at higher stages in the cache\&.
  126. .RE
  127. .PP
  128. \-\-ours, \-\-theirs, \-\-union
  129. .RS 4
  130. Instead of leaving conflicts in the file, resolve conflicts favouring our (or their or both) side of the lines\&. Requires \-\-3way\&.
  131. .RE
  132. .PP
  133. \-\-build\-fake\-ancestor=<file>
  134. .RS 4
  135. Newer
  136. \fIgit diff\fR
  137. output has embedded
  138. \fIindex information\fR
  139. for each blob to help identify the original version that the patch applies to\&. When this flag is given, and if the original versions of the blobs are available locally, builds a temporary index containing those blobs\&.
  140. .sp
  141. When a pure mode change is encountered (which has no index information), the information is read from the current index instead\&.
  142. .RE
  143. .PP
  144. \-R, \-\-reverse
  145. .RS 4
  146. Apply the patch in reverse\&.
  147. .RE
  148. .PP
  149. \-\-reject
  150. .RS 4
  151. For atomicity,
  152. \fIgit apply\fR
  153. by default fails the whole patch and does not touch the working tree when some of the hunks do not apply\&. This option makes it apply the parts of the patch that are applicable, and leave the rejected hunks in corresponding *\&.rej files\&.
  154. .RE
  155. .PP
  156. \-z
  157. .RS 4
  158. When
  159. \fB\-\-numstat\fR
  160. has been given, do not munge pathnames, but use a NUL\-terminated machine\-readable format\&.
  161. .sp
  162. Without this option, pathnames with "unusual" characters are quoted as explained for the configuration variable
  163. \fBcore\&.quotePath\fR
  164. (see
  165. \fBgit-config\fR(1))\&.
  166. .RE
  167. .PP
  168. \-p<n>
  169. .RS 4
  170. Remove <n> leading path components (separated by slashes) from traditional diff paths\&. E\&.g\&., with
  171. \fB\-p2\fR, a patch against
  172. \fBa/dir/file\fR
  173. will be applied directly to
  174. \fBfile\fR\&. The default is 1\&.
  175. .RE
  176. .PP
  177. \-C<n>
  178. .RS 4
  179. Ensure at least <n> lines of surrounding context match before and after each change\&. When fewer lines of surrounding context exist they all must match\&. By default no context is ever ignored\&.
  180. .RE
  181. .PP
  182. \-\-unidiff\-zero
  183. .RS 4
  184. By default,
  185. \fIgit apply\fR
  186. expects that the patch being applied is a unified diff with at least one line of context\&. This provides good safety measures, but breaks down when applying a diff generated with
  187. \fB\-\-unified=0\fR\&. To bypass these checks use
  188. \fB\-\-unidiff\-zero\fR\&.
  189. .sp
  190. Note, for the reasons stated above, the usage of context\-free patches is discouraged\&.
  191. .RE
  192. .PP
  193. \-\-apply
  194. .RS 4
  195. If you use any of the options marked "Turns off
  196. \fIapply\fR" above,
  197. \fIgit apply\fR
  198. reads and outputs the requested information without actually applying the patch\&. Give this flag after those flags to also apply the patch\&.
  199. .RE
  200. .PP
  201. \-\-no\-add
  202. .RS 4
  203. When applying a patch, ignore additions made by the patch\&. This can be used to extract the common part between two files by first running
  204. \fIdiff\fR
  205. on them and applying the result with this option, which would apply the deletion part but not the addition part\&.
  206. .RE
  207. .PP
  208. \-\-allow\-binary\-replacement, \-\-binary
  209. .RS 4
  210. Historically we did not allow binary patch application without an explicit permission from the user, and this flag was the way to do so\&. Currently, we always allow binary patch application, so this is a no\-op\&.
  211. .RE
  212. .PP
  213. \-\-exclude=<path\-pattern>
  214. .RS 4
  215. Don\(cqt apply changes to files matching the given path pattern\&. This can be useful when importing patchsets, where you want to exclude certain files or directories\&.
  216. .RE
  217. .PP
  218. \-\-include=<path\-pattern>
  219. .RS 4
  220. Apply changes to files matching the given path pattern\&. This can be useful when importing patchsets, where you want to include certain files or directories\&.
  221. .sp
  222. When
  223. \fB\-\-exclude\fR
  224. and
  225. \fB\-\-include\fR
  226. patterns are used, they are examined in the order they appear on the command line, and the first match determines if a patch to each path is used\&. A patch to a path that does not match any include/exclude pattern is used by default if there is no include pattern on the command line, and ignored if there is any include pattern\&.
  227. .RE
  228. .PP
  229. \-\-ignore\-space\-change, \-\-ignore\-whitespace
  230. .RS 4
  231. When applying a patch, ignore changes in whitespace in context lines if necessary\&. Context lines will preserve their whitespace, and they will not undergo whitespace fixing regardless of the value of the
  232. \fB\-\-whitespace\fR
  233. option\&. New lines will still be fixed, though\&.
  234. .RE
  235. .PP
  236. \-\-whitespace=<action>
  237. .RS 4
  238. When applying a patch, detect a new or modified line that has whitespace errors\&. What are considered whitespace errors is controlled by
  239. \fBcore\&.whitespace\fR
  240. configuration\&. By default, trailing whitespaces (including lines that solely consist of whitespaces) and a space character that is immediately followed by a tab character inside the initial indent of the line are considered whitespace errors\&.
  241. .sp
  242. By default, the command outputs warning messages but applies the patch\&. When
  243. \fBgit\-apply\fR
  244. is used for statistics and not applying a patch, it defaults to
  245. \fBnowarn\fR\&.
  246. .sp
  247. You can use different
  248. \fI<action>\fR
  249. values to control this behavior:
  250. .sp
  251. .RS 4
  252. .ie n \{\
  253. \h'-04'\(bu\h'+03'\c
  254. .\}
  255. .el \{\
  256. .sp -1
  257. .IP \(bu 2.3
  258. .\}
  259. \fBnowarn\fR
  260. turns off the trailing whitespace warning\&.
  261. .RE
  262. .sp
  263. .RS 4
  264. .ie n \{\
  265. \h'-04'\(bu\h'+03'\c
  266. .\}
  267. .el \{\
  268. .sp -1
  269. .IP \(bu 2.3
  270. .\}
  271. \fBwarn\fR
  272. outputs warnings for a few such errors, but applies the patch as\-is (default)\&.
  273. .RE
  274. .sp
  275. .RS 4
  276. .ie n \{\
  277. \h'-04'\(bu\h'+03'\c
  278. .\}
  279. .el \{\
  280. .sp -1
  281. .IP \(bu 2.3
  282. .\}
  283. \fBfix\fR
  284. outputs warnings for a few such errors, and applies the patch after fixing them (\fBstrip\fR
  285. is a synonym \(em the tool used to consider only trailing whitespace characters as errors, and the fix involved
  286. \fIstripping\fR
  287. them, but modern Gits do more)\&.
  288. .RE
  289. .sp
  290. .RS 4
  291. .ie n \{\
  292. \h'-04'\(bu\h'+03'\c
  293. .\}
  294. .el \{\
  295. .sp -1
  296. .IP \(bu 2.3
  297. .\}
  298. \fBerror\fR
  299. outputs warnings for a few such errors, and refuses to apply the patch\&.
  300. .RE
  301. .sp
  302. .RS 4
  303. .ie n \{\
  304. \h'-04'\(bu\h'+03'\c
  305. .\}
  306. .el \{\
  307. .sp -1
  308. .IP \(bu 2.3
  309. .\}
  310. \fBerror\-all\fR
  311. is similar to
  312. \fBerror\fR
  313. but shows all errors\&.
  314. .RE
  315. .RE
  316. .PP
  317. \-\-inaccurate\-eof
  318. .RS 4
  319. Under certain circumstances, some versions of
  320. \fIdiff\fR
  321. do not correctly detect a missing new\-line at the end of the file\&. As a result, patches created by such
  322. \fIdiff\fR
  323. programs do not record incomplete lines correctly\&. This option adds support for applying such patches by working around this bug\&.
  324. .RE
  325. .PP
  326. \-v, \-\-verbose
  327. .RS 4
  328. Report progress to stderr\&. By default, only a message about the current patch being applied will be printed\&. This option will cause additional information to be reported\&.
  329. .RE
  330. .PP
  331. \-q, \-\-quiet
  332. .RS 4
  333. Suppress stderr output\&. Messages about patch status and progress will not be printed\&.
  334. .RE
  335. .PP
  336. \-\-recount
  337. .RS 4
  338. Do not trust the line counts in the hunk headers, but infer them by inspecting the patch (e\&.g\&. after editing the patch without adjusting the hunk headers appropriately)\&.
  339. .RE
  340. .PP
  341. \-\-directory=<root>
  342. .RS 4
  343. Prepend <root> to all filenames\&. If a "\-p" argument was also passed, it is applied before prepending the new root\&.
  344. .sp
  345. For example, a patch that talks about updating
  346. \fBa/git\-gui\&.sh\fR
  347. to
  348. \fBb/git\-gui\&.sh\fR
  349. can be applied to the file in the working tree
  350. \fBmodules/git\-gui/git\-gui\&.sh\fR
  351. by running
  352. \fBgit\fR
  353. \fBapply\fR
  354. \fB\-\-directory=modules/git\-gui\fR\&.
  355. .RE
  356. .PP
  357. \-\-unsafe\-paths
  358. .RS 4
  359. By default, a patch that affects outside the working area (either a Git controlled working tree, or the current working directory when "git apply" is used as a replacement of GNU patch) is rejected as a mistake (or a mischief)\&.
  360. .sp
  361. When
  362. \fBgit\fR
  363. \fBapply\fR
  364. is used as a "better GNU patch", the user can pass the
  365. \fB\-\-unsafe\-paths\fR
  366. option to override this safety check\&. This option has no effect when
  367. \fB\-\-index\fR
  368. or
  369. \fB\-\-cached\fR
  370. is in use\&.
  371. .RE
  372. .PP
  373. \-\-allow\-empty
  374. .RS 4
  375. Don\(cqt return an error for patches containing no diff\&. This includes empty patches and patches with commit text only\&.
  376. .RE
  377. .SH "CONFIGURATION"
  378. .sp
  379. Everything below this line in this section is selectively included from the \fBgit-config\fR(1) documentation\&. The content is the same as what\(cqs found there:
  380. .PP
  381. apply\&.ignoreWhitespace
  382. .RS 4
  383. When set to
  384. \fIchange\fR, tells
  385. \fIgit apply\fR
  386. to ignore changes in whitespace, in the same way as the
  387. \fB\-\-ignore\-space\-change\fR
  388. option\&. When set to one of: no, none, never, false, it tells
  389. \fIgit apply\fR
  390. to respect all whitespace differences\&. See
  391. \fBgit-apply\fR(1)\&.
  392. .RE
  393. .PP
  394. apply\&.whitespace
  395. .RS 4
  396. Tells
  397. \fIgit apply\fR
  398. how to handle whitespace, in the same way as the
  399. \fB\-\-whitespace\fR
  400. option\&. See
  401. \fBgit-apply\fR(1)\&.
  402. .RE
  403. .SH "SUBMODULES"
  404. .sp
  405. If the patch contains any changes to submodules then \fIgit apply\fR treats these changes as follows\&.
  406. .sp
  407. If \fB\-\-index\fR is specified (explicitly or implicitly), then the submodule commits must match the index exactly for the patch to apply\&. If any of the submodules are checked\-out, then these check\-outs are completely ignored, i\&.e\&., they are not required to be up to date or clean and they are not updated\&.
  408. .sp
  409. If \fB\-\-index\fR is not specified, then the submodule commits in the patch are ignored and only the absence or presence of the corresponding subdirectory is checked and (if possible) updated\&.
  410. .SH "SEE ALSO"
  411. .sp
  412. \fBgit-am\fR(1)\&.
  413. .SH "GIT"
  414. .sp
  415. Part of the \fBgit\fR(1) suite