在 git 中,如何为最近 2 个以上的修订版创建单个补丁?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2217452/
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
In git, how do I create a single patch for the last 2+ revisions?
提问by Matthew
I would like to create a patch for the last 2 revisions.
我想为最近的 2 个修订版创建一个补丁。
git format-patch -2
gives me 2 patch files, one for each revision
给我 2 个补丁文件,每个修订版一个
git format-patch HEAD~2..HEAD
gives the same thing.
给出同样的东西。
git format-patch -1 HEAD~2..HEAD
gives a single file, but only contains changes for the last revision.
给出一个文件,但只包含上次修订的更改。
Is there any way to do this in git?
有没有办法在 git 中做到这一点?
采纳答案by Tobu
git diff HEAD~2..HEAD > my-patch.diff
It won't have any of format-patch's per-commit metadata, though.
不过,它不会有任何格式补丁的每次提交元数据。
回答by JC Brand
Use the --stdout option and then cat it to a file.
使用 --stdout 选项,然后将其转换为文件。
Like so:
像这样:
git format-patch HEAD~2..HEAD --stdout > changes.patch
This will keep the per-commit metadata.
这将保留每次提交的元数据。
回答by VonC
With Git 2.20 (Q4 2018) and more, you now have:
使用 Git 2.20(2018 年第四季度)及更多版本,您现在拥有:
git format-patch --interdiff
.git format-patch --rangediff
.
git format-patch --interdiff
.git format-patch --rangediff
.
Both are helping to explain the difference between this version and the previous attempt in the cover letter (or after the tree-dashes as a comment).
两者都有助于解释此版本与求职信中(或在树状虚线后作为评论)中的先前尝试之间的区别。
format-patch
: allow--interdiff
/--rangediff
to apply to a lone-patchWhen submitting a revised version of a patch or series, it can be helpful (to reviewers) to include a summary of changes since the previous attempt in the form of an interdiff, typically in the cover letter.
However, it is occasionally useful, despite making for a noisy read, to insert an interdiff or a rangediff into the commentary section of the lone patch of a 1-patch series.
format-patch
: 允许--interdiff
/--rangediff
应用于一个单独的补丁在提交补丁或系列的修订版本时,(对审阅者)以 interdiff 的形式(通常在求职信中)包含自上次尝试以来的更改摘要可能会有所帮助。
但是,尽管读取时会产生噪音,但偶尔将 interdiff 或 rangediff 插入 1-patch 系列的单独补丁的注释部分也是有用的。
See commit ee6cbf7, commit 3fcc7a2, commit 3b02641, commit 5ac290f, commit 126facf, commit fa5b7ea(22 Jul 2018) by Eric Sunshine (sunshineco
).
(Merged by Junio C Hamano -- gitster
--in commit 688cb1c, 17 Sep 2018)
请参阅Eric Sunshine ( ) 的commit ee6cbf7、commit 3fcc7a2、commit 3b02641、commit 5ac290f、commit 126facf、commit fa5b7ea(2018 年 7 月 22 日)。(由Junio C Hamano合并-- --在提交 688cb1c,2018 年 9 月 17 日)sunshineco
gitster
Therefore, extend "
git format-patch --interdiff=<prev>
" to insert an interdiff into the commentary section of a lone patch rather than requiring a cover letter.
The interdiff is indented to avoid confusinggit-am
and human readers into considering it part of the patch proper.
因此,扩展“
git format-patch --interdiff=<prev>
”以在单独补丁的评论部分插入一个interdiff,而不是需要一封求职信。
interdiff 是缩进的,以避免混淆git-am
和人类读者将其视为补丁程序的一部分。
See commit 40ce416, commit 8631bf1, commit 4ee9968, commit 2e6fd71, commit 31e2617, commit 73a834e, commit 2566865, commit 87f1b2d(22 Jul 2018) by Eric Sunshine (sunshineco
).
(Merged by Junio C Hamano -- gitster
--in commit 881c019, 17 Sep 2018)
见提交40ce416,提交8631bf1,提交4ee9968,提交2e6fd71,提交31e2617,提交73a834e,提交2566865,提交87f1b2d(2018年7月22日)由埃里克阳光(sunshineco
)。
(由Junio C gitster
Hamano合并-- --在提交 881c019 中,2018 年 9 月 17 日)
Therefore, extend "
git format-patch --range-diff=<refspec>
" to insert arange-diff
into the commentary section of a lone patch rather than requiring a cover letter.
因此,扩展“
git format-patch --range-diff=<refspec>
”以range-diff
在单独补丁的评论部分插入一个,而不是需要一个求职信。
回答by William Pursell
You could do something like:
你可以这样做:
$ git checkout -b tmp $ git reset HEAD~2 $ git commit -a
The commit to branch tmp will be the same as the 2 individual commits.
对分支 tmp 的提交将与 2 个单独的提交相同。