예배 규칙서 찾다
Guides gitattributes giteveryday gitglossary gitignore gitmodules gitrevisions gittutorial gitworkflows Administration git archive git bundle git clean git filter-branch git fsck git gc git instaweb git reflog Basic Snapshotting git add git commit git diff git mv git reset git rm git status Branching and Merging git branch git checkout git log git merge git mergetool git stash git tag Debugging git bisect git blame git grep Email git am git format-patch git request-pull git send-email External Systems git fast-import git svn Getting and Creating Projects git clone git init Git git annotate git archimport git bisect-lk2009 git check-attr git check-mailmap git check-ref-format git checkout-index git cherry git citool git column git credential git credential-cache git credential-store git cvsexportcommit git cvsimport git cvsserver git diff-files git diff-tree git difftool git fast-export git fetch-pack git fmt-merge-msg git get-tar-commit-id git gui git http-backend git http-fetch git http-push git imap-send git index-pack git interpret-trailers git ls-remote git ls-tree git mailinfo git mailsplit git merge-file git merge-index git merge-one-file git merge-tree git mktag git mktree git name-rev git notes git p4 git pack-objects git pack-redundant git pack-refs git parse-remote git patch-id git prune git prune-packed git quiltimport git receive-pack git remote-ext git remote-fd git remote-testgit git repack git replace git rerere git send-pack git sh-i18n git sh-setup git shell git show-branch git show-index git stripspace git unpack-file git unpack-objects git upload-archive git upload-pack git var git verify-commit git verify-tag git whatchanged git worktree Inspection and Comparison git describe git shortlog git show Miscellaneous api credentials api index gitcli gitcore tutorial gitcredentials gitcvs migration gitdiffcore githooks gitk gitnamespaces gitremote helpers gitrepository layout gitsubmodules gittutorial 2 gitweb gitweb.conf pack format User Manual Patching git apply git cherry-pick git rebase git revert Plumbing Commands git cat-file git check-ignore git commit-tree git count-objects git diff-index git for-each-ref git hash-object git ls-files git merge-base git read-tree git rev-list git rev-parse git show-ref git symbolic-ref git update-index git update-ref git verify-pack git write-tree Server Admin git daemon git update-server-info Setup and Config git git config git help Sharing and Updating Projects git fetch git pull git push git remote git submodule
문자

命名

git-apply  - 将补丁应用于文件和/或索引

概要

git apply [--stat] [--numstat] [--summary] [--check] [--index] [--3way]          [--apply] [--no-add] [--build-fake-ancestor=<file>] [-R | --reverse]          [--allow-binary-replacement | --binary] [--reject] [-z]          [-p<n>] [-C<n>] [--inaccurate-eof] [--recount] [--cached]          [--ignore-space-change | --ignore-whitespace]          [--whitespace=(nowarn|warn|fix|error|error-all)]          [--exclude=<path>] [--include=<path>] [--directory=<root>]          [--verbose] [--unsafe-paths] [<patch>…]

描述

读取提供的差异输出(即“一个补丁”)并将其应用于文件。从存储库中的子目录运行时,目录外的修补路径将被忽略。使用该--index选项,修补程序也应用于索引,并使用该--cached选项将修补程序应用于索引。如果没有这些选项,该命令仅将修补程序应用于文件,并且不要求它们位于 Git 存储库中。

此命令应用修补程序,但不创建提交。使用 git-am [1] 创建 git-format-patch [1] 生成的补丁和/或通过电子邮件接收的补丁。

选项

<patch>…

从中读取补丁的文件。-可以用来从标准输入中读取。

--stat

输出 diffstat 代替输入补丁。关闭“适用”。

--numstat

--stat与之类似,但显示十进制表示法中添加和删除的行数以及不带缩写的路径名,以使其更加机器友好。对于二进制文件,输出两个-而不是说0 0。关闭“适用”。

--summary

输出从 git diff 扩展头获取的信息(例如创建,重命名和模式更改)的精简摘要,而不是应用该修补程序。关闭“适用”。

--check

而不是应用修补程序,查看修补程序是否适用于当前工作树和/或索引文件并检测错误。关闭“适用”。

--index

--check生效或应用修补程序(当没有任何禁用修补程序的选项时,这是默认设置)时,请确保修补程序适用于当前索引文件记录的内容。如果要在工作树中修补的文件不是最新的,则会将其标记为错误。该标志也会导致索引文件被更新。

--cached

在不接触工作树的情况下应用补丁。取而代之的是缓存数据时应用补丁,并将结果存储在索引中,而不使用工作树。这暗示--index

-3   --3way

如果修补程序不能干净地应用,如果修补程序记录它应该应用的斑点的标识,则回退到3路合并,并且我们在本地可以使用这些斑点,可能会在工作树中的文件中留下冲突标记供用户解决。此选项隐含--index期权,并与不兼容--reject--cached选项。

--build-fake-ancestor=<file>

为每个 blob git diff嵌入更新的输出index information以帮助识别该修补程序适用的原始版本。当给出这个标志,并且如果原始版本的 blob 在本地可用,则建立包含这些 blob 的临时索引。

遇到纯模式更改(没有索引信息)时,将从当前索引读取信息。

-R   --reverse

反向应用补丁。

--reject

对于原子性,git apply默认情况下会失败整个修补程序,并且在某些区块不适用时不会触及工作树。该选项使它应用可用的补丁部分,并将被拒绝的宏保留在对应的 * .rej 文件中。

-z

--numstat给出时,请勿使用路径名,但使用 NUL 终止的机器可读格式。

如果没有这个选项,带有“不寻常”字符的路径名将按照配置变量的说明引用core.quotePath(请参阅 git-config [1] )。

-p<n>

从传统差异路径中删除 <n> 引导斜杠。默认值是1。

-C<n>

确保每次更改之前和之后至少有 <n> 行周围环境匹配。当存在较少的周围环境线时,它们都必须匹配。默认情况下,不会忽略上下文。

--unidiff-zero

默认情况下,git apply预计所应用的修补程序是至少包含一行上下文的统一差异。这提供了良好的安全措施,但在应用使用生成的差异时发生故障--unified=0。绕过这些检查使用--unidiff-zero

请注意,由于上述原因,不鼓励使用上下文无关的修补程序。

--apply

如果您使用apply上面标记为“关闭”的任何选项,则git apply读取并输出所请求的信息,而不实际应用该补丁。在这些标志之后给这个标志也应用补丁。

--no-add

应用修补程序时,忽略修补程序添加的内容。这可以用来提取两个文件之间的公共部分,方法是首先diff在这两个文件上运行,并使用此选项应用结果,该选项将应用删除部分,但不应用添加部分。

--allow-binary-replacement   --binary

从历史上看,我们不允许在未经用户明确许可的情况下应用二进制补丁,并且此标志是实现此目的的方式。目前我们总是允许二进制补丁程序应用程序,所以这是一个无操作。

--exclude=<path-pattern>

不要将更改应用于与给定路径模式匹配的文件。这在导入补丁集时很有用,您想要排除某些文件或目录。

--include=<path-pattern>

将更改应用于与给定路径模式匹配的文件。这在导入补丁集时很有用,您想要在其中包含某些文件或目录。

在使用模式--exclude--include模式时,将按照它们在命令行上出现的顺序进行检查,并且第一个匹配将确定是否使用每个路径的修补程序。缺省情况下,如果命令行中没有包含模式,则缺省使用不匹配任何包含/排除模式的路径补丁,如果有任何包含模式则忽略该补丁。

--ignore-space-change   --ignore-whitespace

应用修补程序时,如果需要,请忽略上下文行中空白的更改。上下文行将保留它们的空白,并且不管--whitespace选项的值如何,它们都不会进行空白修复。虽然新的线路仍然是固定的。

--whitespace=<action>

应用修补程序时,检测具有空白错误的新行或修改过的行。认为空白错误是由core.whitespace配置控制的。默认情况下,尾随空格(包括单独由空格组成的行)和空格字符(紧跟该行的初始缩进内的制表符后面的空格字符)将被视为空白错误。

默认情况下,该命令输出警告消息但应用修补程序。当git-apply用于统计而不应用补丁时,它默认为nowarn

您可以使用不同的<action>值来控制此行为:

  • nowarn 关闭后面的空格警告。

  • warn 输出一些此类错误的警告,但按原样应用该补丁(默认)。

  • fix输出一些此类错误的警告,并在修复它们之后应用修补程序(strip是同义词---该工具仅用于考虑尾部空白字符作为错误,并且修复涉及stripping它们,但现代 Gits 做得更多)。

  • error 输出一些此类错误的警告,并拒绝应用该修补程序。

  • error-all类似error但显示所有错误。

--inaccurate-eof

在某些情况下,某些版本diff不能在文件末尾正确检测到缺失的新行。因此,这些程序创建的补丁diff不会正确记录不完整的行。此选项通过解决此错误来增加对应用此类修补程序的支持。

-v   --verbose

将进展报告给 stderr 。默认情况下,只会打印有关当前正在应用的修补程序的消息。该选项会导致报告其他信息。

--recount

不要相信 hunk headers 中的行数,但通过检查补丁来推断它们(例如,在编辑补丁而不适当调整 hunk headers 之后)。

--directory=<root>

将 <root> 加入所有文件名。如果还传递了“-p”参数,则在应用新根之前应用该参数。

例如,谈到更新补丁a/git-gui.shb/git-gui.sh可以应用到文件中的工作树modules/git-gui/git-gui.sh运行git apply --directory=modules/git-gui

--unsafe-paths

默认情况下,影响工作区域以外的补丁( Git 控制的工作树或当 “git apply” 用作 GNU 补丁的替代品时的当前工作目录)被拒绝为错误(或恶作剧)。

git apply用作“更好的 GNU 补丁”时,用户可以通过--unsafe-paths选项来覆盖此安全检查。此选项在使用--index--cached不使用时无效。

组态

apply.ignoreWhitespace

设置为change如果您想要默认情况下忽略空白的更改。设置为以下之一:否,无,从不,如果希望空格中的更改变得显着,则为false。

apply.whitespace

当没有--whitespace从命令行给出标志时,这个配置项被用作默认值。

子模块

如果修补程序包含对子模块的任何更改,则按git apply如下方式处理这些更改。

如果--index指定(明确或隐含地),则子模块提交必须完全匹配要应用的修补程序的索引。如果有任何子模块被检出,则这些检出完全被忽略,即它们不需要是最新的或清洁的,并且它们不被更新。

如果--index未指定,则补丁中的子模块落实将被忽略,只会检查是否存在相应的子目录,并且(如果可能)更新。

이전 기사: 다음 기사: