git format-patch 用法参考
git format-patch [(-o|--output-directory) <dir> | --stdout]
[ <since> | <revision range> ]
There are two ways to specify which commits to operate on.
A single commit, since, specifies that the commits leading to the tip of the current branch that are not in the history that leads to the since to be output.
Generic revision range expression (see “SPECIFYING REVISIONS” section in gitrevisions(7)) means the commits in the specified range.
The first rule takes precedence in the case of a single commmit. To apply the second rule, i.e., format everything since the beginning of history up until commmit, use the –root option: git format-patch –root commmit. If you want to format only commmit itself, you can do this with git format-patch -1 commmit.
git format-patch 与 git diff 的功能比较
功能比较
使用 git format-patch
创建的补丁还将包含有关 commit(committer,date,commit message,…)的一些元信息,并将包含二进制数据的差异。 所有内容都将被格式化为一个邮件,以便它可以很容易地发送。 接收它的人可以使用 git am
重新创建相应的提交,所有元数据将保持不变。 它也可以应用于 git apply
,因为它是一个简单的 diff
的超级集。
用 git diff
填充的补丁将是一个简单的 diff
与上下文(think diff -u )。 它也可以应用于 git apply
但不会重新创建元数据(因为它们不存在)。
总而言之, git format-patch
对传输 commit 是有用的,而 git diff
对于在两个树之间获得差异很有用。
操作对象比较
git format-patch
用于生成不同 commit 的之间的差异。
git diff
除了生成不同 commit 的之间的差异,还可以生成:“commit 与 index”、“index 与工作区”及 “commit 与工作区”的差异。
参考
What is the difference between ‘git format-patch’ and ‘git diff’?