git am 和 git apply 有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12240154/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the difference between git am and git apply?
提问by Christoph
Both git am
and git apply
can be used to apply patches. I fail to see the difference. I see a difference now: git am
automatically commits whereas git apply
only touches the files but doesn't create a commit. Is that the only difference?
双方git am
并git apply
可以用来应用补丁。我看不出区别。我现在看到了一个不同之处:git am
自动提交而git apply
只涉及文件但不创建提交。这是唯一的区别吗?
回答by georgebrock
Both the input and output are different:
输入和输出都不同:
git apply
takes a patch (e.g. the output ofgit diff
) and applies it to the working directory (or index, if--index
or--cached
is used).git am
takes a mailbox of commits formatted as an email messages (e.g. the output ofgit format-patch
) and applies them to the current branch.
git apply
获取补丁(例如 的输出git diff
)并将其应用于工作目录(或索引,如果使用--index
或--cached
)。git am
接收一个邮箱格式的提交邮件(例如 的输出git format-patch
)并将它们应用到当前分支。
git am
uses git apply
behind the scenes, but does more work before (reading a Maildir
or mbox
, and parsing email messages) and after (creating commits).
git am
git apply
在幕后使用,但在之前(阅读Maildir
或mbox
,并解析电子邮件)和之后(创建提交)做了更多的工作。
回答by CB Bailey
git apply
is for applying straight diffs (e.g. from git diff
) whereas git am
is for applying patches and sequences of patches from emails, either mbox or Maildir format and is the "opposite" of git format-patch
. git am
tries to extract commit messages and author details from email messages which is why it can make commits.
git apply
用于应用直接差异(例如 from git diff
),而git am
用于应用来自电子邮件的补丁和补丁序列,无论是 mbox 还是 Maildir 格式,并且是git format-patch
. git am
尝试从电子邮件消息中提取提交消息和作者详细信息,这就是它可以进行提交的原因。
回答by 0x90
With git am
you apply the patch so if you use git status
you won't see any local changes.
随着git am
应用修补程序,所以如果你使用git status
,你不会看到任何地方的变化。
git apply
enables you to make the changes in the source files as if you were writing the code by yourself, consequently git status
and git diff
will output the changes made in the patch you have applied, then you can fix/add more changes and submit them together as one new patch.
git apply
使您可以更改在源文件中,如果你是自己编写的代码,因此git status
而git diff
将输出在您已经应用,那么你就可以修复/添加更多的变化,并一起提交它们作为一个新的补丁的补丁所做的更改.