'git format-patch和'git diff'有什么区别? [英] What is the difference between 'git format-patch and 'git diff'?

查看:564
本文介绍了'git format-patch和'git diff'有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有看到'git format-patch'和'git diff'的输出有什么不同,有没有区别?我不能使用'git diff'生成补丁,然后使用git apply?



我的问题是我添加了更改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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆