'git format-patch和'git diff'有什么区别? [英] What is the difference between 'git format-patch and 'git diff'?
问题描述
我的问题是我添加了更改index,但显然git format-patch只接受提交,所以如果我可以使用diff的输出,那么我可以使用这个命令为索引中的更改生成一个补丁:
git diff --cached> index.patch
c> git format-patch 还将包含一些关于提交(提交者,日期,提交消息,...)的元信息,并将包含二进制数据的差异。所有内容都将被格式化为邮件,以便轻松发送。接收它的人可以用 git am
重新创建相应的提交,并且所有元数据都将保持不变。它也可以应用于 git apply
,因为它是一个简单差异的超级集合。
一个补丁使用> git diff
来创建一个带有上下文的简单差异(请考虑 diff -u
)。它也可以用 git apply
应用,但不会重新创建元数据(因为它们不存在)。
总之, git format-patch
对传输提交很有用,而 git diff
对于获取两棵树之间的差异。
I don't see a difference between the output of 'git format-patch' and 'git diff', is there any? And won't I be able to use 'git diff' to produce a patch and then apply it using git apply?
My problem is that I have changes added to the index, but apparently git format-patch only accepts commits, so if I can use the output of diff, then I can use this command to produce a patch for the changes in the index:
git diff --cached > index.patch
A patch created with git format-patch
will also include some meta-information about the commit (committer, date, commit message, ...) and will contains diff of binary data. Everything will be formatted as a mail, so that it can be easily sent. The person that receive it can then recreate the corresponding commit with git am
and all meta-data will be intact. It can also be applied with git apply
as it is a super-set of a simple diff.
A patch crated with git diff
will be a simple diff with context (think diff -u
). It can also be applied with git apply
but the meta-data will not be recreated (as they are not present).
In summary, git format-patch
is useful to transmit a commit, while git diff
is useful to get a diff between two trees.
这篇关于'git format-patch和'git diff'有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!