在 git 中,如何为最后 2+ 创建单个补丁?修订?

发布于 2024-08-20 12:53:55 字数 286 浏览 3 评论 0 原文

我想为最后两个修订创建一个补丁。

git format-patch -2

给了我 2 个补丁文件,每个修订版

git format-patch HEAD~2..HEAD

都有一个相同的东西。

git format-patch -1 HEAD~2..HEAD

给出单个文件,但仅包含最后修订版的更改。

在git中有什么办法可以做到这一点吗?

I would like to create a patch for the last 2 revisions.

git format-patch -2

gives me 2 patch files, one for each revision

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

输什么也不输骨气 2024-08-27 12:53:55
git diff HEAD~2..HEAD > my-patch.diff

不过,它不会有任何 format-patch 的每次提交元数据。

git diff HEAD~2..HEAD > my-patch.diff

It won't have any of format-patch's per-commit metadata, though.

小ぇ时光︴ 2024-08-27 12:53:55

使用 --stdout 选项,然后将其放入文件中。

像这样:

git format-patch HEAD~2..HEAD --stdout > changes.patch

这将保留每次提交的元数据。

Use the --stdout option and then cat it to a file.

Like so:

git format-patch HEAD~2..HEAD --stdout > changes.patch

This will keep the per-commit metadata.

不念旧人 2024-08-27 12:53:55

使用 Git 2.20(2018 年第 4 季度)及更高版本,您现在拥有:

  • git format-patch --interdiff
  • git format-patch --rangediff 。

两者都有助于解释此版本与求职信中之前的尝试(或在树破折号之后作为评论)之间的差异。

format-patch:允许 --interdiff / --rangediff 应用于单独补丁

在提交补丁或系列的修订版本时,以 Interdiff 的形式(通常在求职信中)包含自上次尝试以来的更改摘要可能会有所帮助。
然而,尽管会造成阅读噪音,但在 1 个补丁系列的单个补丁的注释部分插入 interdiff 或 rangediff 偶尔还是有用的。

请参阅 提交 ee6cbf7提交 3fcc7a2, 提交3b02641提交 5ac290f提交126facf提交 fa5b7ea(2018 年 7 月 22 日),作者:Eric Sunshine (sunshineco)
(由 Junio C Hamano -- gitster -- 合并于 提交 688cb1c,2018 年 9 月 17 日)

因此,扩展“git format-patch --interdiff=

”以将 interdiff 插入到单个补丁的注释部分,而不需要求职信。
interdiff 是缩进的,以避免混淆 git-am 和人类读者,使其将其视为补丁的一部分。

请参阅 提交 40ce416提交 8631bf1, 提交4ee9968提交 2e6fd71提交 31e2617提交 73a834e提交 2566865提交 87f1b2d(2018 年 7 月 22 日),作者:Eric Sunshine (sunshineco)
(由 Junio C Hamano -- gitster -- 合并于 提交 881c019,2018 年 9 月 17 日)

因此,扩展“git format-patch --range-diff=”以将 range-diff 插入到单个补丁的注释部分而不是需要求职信。


使用 Git 2.46(2024 年第 3 季度),第 15 批,“git format-patch --interdiff"(man) 对于多补丁系列,学会了自动打开求职信(除非被告知永远不要使用“--no-cover-letter”等启用求职信) )。

请参阅提交f96c385提交 bc665cd(2024 年 6 月 7 日),作者:Rubén Justo (rjusto
(由 Junio C Hamano -- gitster -- 合并于 提交 9071453,2024 年 6 月 20 日)

格式补丁:假设--cover -多补丁系列中差异的字母

签字人:Rubén Justo

当我们在 git-format-patch(1) 中处理多补丁系列时,如果我们看到 --interdiff--range-diff 但没有--cover-letter,我们返回一个错误,内容如下:

致命:--range-diff 需要 --cover-letter 或单个补丁

或者:

致命:--interdiff 需要 --cover-letter 或单个补丁

这是有道理的,因为求职信是我们放置与先前版本的差异的地方。

但是,考虑到 format-patch 根据需要生成多补丁,让我们在使用 --interdiff 时采用类似的“必要时覆盖”方法>--范围差异

因此,当用户说 --iterdiff--range 时,放宽多补丁系列中对显式 --cover-letter 的要求-diff.

不过,如果只是为了返回错误,请遵守“format.coverLetter=no”和--no-cover-letter

With Git 2.20 (Q4 2018) and more, you now have:

  • 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-patch

When 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.

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)

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 confusing git-am and human readers into considering it part of the patch proper.

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)

Therefore, extend "git format-patch --range-diff=<refspec>" to insert a range-diff into the commentary section of a lone patch rather than requiring a cover letter.


With Git 2.46 (Q3 2024), batch 15, "git format-patch --interdiff"(man) for multi-patch series learned to turn on cover letters automatically (unless told never to enable cover letter with "--no-cover-letter" and such).

See commit f96c385, commit bc665cd (07 Jun 2024) by Rubén Justo (rjusto).
(Merged by Junio C Hamano -- gitster -- in commit 9071453, 20 Jun 2024)

format-patch: assume --cover-letter for diff in multi-patch series

Signed-off-by: Rubén Justo

When we deal with a multi-patch series in git-format-patch(1), if we see --interdiff or --range-diff but no --cover-letter, we return with an error, saying:

fatal: --range-diff requires --cover-letter or single patch

or:

fatal: --interdiff requires --cover-letter or single patch

This makes sense because the cover-letter is where we place the diff from the previous version.

However, considering that format-patch generates a multi-patch as needed, let's adopt a similar "cover as necessary" approach when using --interdiff or --range-diff.

Therefore, relax the requirement for an explicit --cover-letter in a multi-patch series when the user says --iterdiff or --range-diff.

Still, if only to return the error, respect "format.coverLetter=no" and --no-cover-letter.

终陌 2024-08-27 12:53:55

您可以执行以下操作:

$ git checkout -b tmp
$ git reset HEAD~2
$ git commit -a

对分支 tmp 的提交将与 2 个单独的提交相同。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文