当不进行樱桃采摘时,之前的樱桃采摘现在为空

发布于 2025-01-19 07:29:15 字数 418 浏览 0 评论 0 原文

我正在尝试使用 git rebase -i HEAD~19 删除提交列表。我过去曾成功使用过此方法,但是当我尝试运行然后退出 vim 而不进行任何更改(:q!)时,我收到此错误:

The previous cherry-pick is now empty, possibly due to conflict resolution.
If you wish to commit it anyway, use:

    git commit --allow-empty

Otherwise, please use 'git cherry-pick --skip'
interactive rebase in progress; onto dd0b851

我不是樱桃选择并且不确定为什么我会收到要跳过的错误。

I am trying to drop a list of commits by using git rebase -i HEAD~19. I have successfully used this method in the past, but when I try running and then quitting vim without any changes(:q!) I get this error:

The previous cherry-pick is now empty, possibly due to conflict resolution.
If you wish to commit it anyway, use:

    git commit --allow-empty

Otherwise, please use 'git cherry-pick --skip'
interactive rebase in progress; onto dd0b851

I am not cherry picking and not sure why I'm getting an error to skip.

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

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

发布评论

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

评论(2

ˉ厌 2025-01-26 07:29:15

发生这种情况是因为您没有做您认为正在做的事情:

但是当我尝试运行然后退出 vim 而不做任何更改(:q!)...

当您退出而不修改该文件时,您实际上仍在进行变基。 如果您想退出而不进行变基,您应该删除文件中的所有行(或至少删除包含提交的每一行),然后保存并退出。这将显示错误并中止变基。

退出通常会起作用,而似乎什么也不做,是因为当你的历史记录是线性的时,默认情况下,如果没有任何关于提交的信息,Git 不会重写提交。提交已更改,因此它保留原始提交 ID 并继续。这就是为什么您仍然看到“rebasing 1/X...”,因为它会迭代所有提交,但实际上并没有重写它们。

如果您的历史记录不是线性的(意味着您有一些合并提交包含在变基中),则合并提交不会包含在待办事项列表中。因此,这次变基实际上将重写至少一些提交,因为您在此重写中缺少合并提交,因此图表并不相同。在变基期间,如果遇到没有更改的提交,您将收到您看到的消息。它停在这里是因为这被认为是不寻常的,它让您有机会决定要做什么。它提到cherry-pick的原因是因为在幕后,在rebase期间重写提交本质上是为您对每个提交进行cherry-pick。

旁注:在这种情况下,最有可能出现空提交的原因是合并提交的两侧都有类似的提交(rebase 待办事项列表中缺少该提交)。

This is happening because you aren't doing what you think you're doing:

but when I try running and then quitting vim without any changes(:q!)...

When you quit without modifying that file, you are actually still doing the rebase. If you want to exit without doing the rebase, you should delete all the lines in the file (or at least every line that contains a commit on it), and then save and exit. This will display an error and abort the rebase.

The reason just exiting usually works, and appears to do nothing, is because when your history is linear, by default Git won't rewrite a commit if nothing at all about the commit has changed, so it keeps the original commit ID and moves on. This is why you still see "rebasing 1/X..." as it iterates through all the commits and doesn't actually re-write them.

If you history is not linear (meaning you have some merge commits included in the rebase), the merge commits are not included in the to-do list. So this time rebasing will actually rewrite at least some of the commits, because you are missing the merge commits in this rewrite so the graph isn't identical. During the rebase, if it encounters a commit with no changes in it, you will get the message you saw. It stops here because this is considered unusual and it gives you the opportunity to decide what to do. The reason it mentions cherry-pick is because behind the scenes, rewriting commits during a rebase is essentially doing a cherry-pick of each commit for you.

Side Note: the most likely reason that you would have empty commits in this situation is when you have a similar commit on both sides of a merge commit (which is missing from the rebase to-do list).

娇纵 2025-01-26 07:29:15

您可能需要 git rebase - -empty(=drop|keep|ask) 选项:

如何处理那些开始时不为空且不是任何上游提交的干净精选,但在变基后变空的提交(因为它们包含已经上游更改的子集)。
使用 drop(默认),变空的提交将被删除。

这特别有用(现在是 2024 年第二季度),因为由 git rebase 在后台完成的 gitcherry-pick 也理解 --empty(=drop|keep|询问)

使用 Git 2.45(2024 年第 2 季度),第 14 批,允许 git-cherry-pick(1)通过新的 --empty 选项自动删除冗余提交,类似于git-rebase(1) 和 git-am(1) 的 --empty 选项。

请参阅 提交 ec79d76提交 bd2f9fd, 提交 661b671, 提交 1b90588, 提交 c282eba, 提交 64a443e, 提交 0af3889(2024 年 3 月 25 日),作者:布莱恩·莱尔斯(brianmlyles
(由 Junio C Hamano -- gitster -- 合并于 提交 17381ab,2024 年 4 月 3 日)

cherry-pick:添加 --empty 用于更强大的冗余提交处理

签字人:Brian Lyles

git-rebase(1) 和 git-am(1) 一样,git-cherry-pick(1) 也可以产生如果所选提交的内容已存在于目标历史记录中,则提交将变得多余。
但是,git-cherry-pick(1) 没有与 git-rebase(1) 和 git-am( 1)有。

可以通过这些冗余提交完成三件事:删除它们、保留它们,或者让cherry-pick停止并等待用户采取操作。
git-rebase(1) 在 --empty 选项="nofollow noreferrer">提交 e98c426 ("rebase (交互式后端):修复空提交的处理”,2020-02-15,Git v2.26.0-rc0 -- 合并 列出batch #8),它处理所有这三种情况。
同样,git-am(1) 在 --empty rel="nofollow noreferrer">7c096b8 ("am: 支持--empty= 处理空补丁", 2021-12-09, Git v2.35.0-rc0 -- 第 7 批)。

git-cherry-pick另一方面,(1) 仅支持三种可能性中的两种:通过 --keep-redundant-commits 保留冗余提交,或者由于不指定该选项而导致挑选失败。
没有办法自动删除多余的提交。

为了使 git-cherry-pick(1) 与 git-rebase(1) 和 git-am 更加一致>(1),此提交向 git-cherry-pick(1) 添加了一个 --empty 选项。
它具有相同的三个选项(keepdropstop),并且大部分行为相同。
显着的区别是,对于 git-cherry-pick(1),默认值为 stop,在未指定选项时保持当前行为。

与现有的 --keep-redundant-commits 一样,--empty=keep 将暗示 --allow-empty

--keep-redundant-commits 选项将被记录为 --empty=keep 的已弃用同义词,并且暂时将支持向后兼容存在。

gitcherry-pick 现在包含在其 手册页

先前的提交将导致cherry-pick失败。为了强制
包含这些提交,请使用 --empty=keep

gitcherry-pick 现在包含在其 手册页

--empty=(drop|keep|stop)

如何处理被精心挑选的冗余提交
当前历史中已经发生了变化。

--
删除;;
提交将被删除。
保留;;
提交将被保留。暗示--allow-empty
停止;;
当应用提交时,cherry-pick 将停止,从而允许
你来检查提交。这是默认行为。

请注意,--empty=drop--empty=stop 仅指定如何处理
最初不是空的提交,而是由于之前的操作而变成空的
犯罪。最初为空的提交仍然会导致樱桃选择
除非指定 --empty=keep--allow-empty 之一,否则失败。

You might need to git rebase --empty(=drop|keep|ask) option:

How to handle commits that are not empty to start and are not clean cherry-picks of any upstream commit, but which become empty after rebasing (because they contain a subset of already upstream changes).
With drop (the default), commits that become empty are dropped.

This is especially useful (now Q2 2024) because the git cherry-pick done in the background by git rebase also understand --empty(=drop|keep|ask)

With Git 2.45 (Q2 2024), batch 14, allow git-cherry-pick(1) to automatically drop redundant commits via a new --empty option, similar to the --empty options for git-rebase(1) and git-am(1).

See commit ec79d76, commit bd2f9fd, commit 661b671, commit 1b90588, commit c282eba, commit 64a443e, commit 0af3889 (25 Mar 2024) by Brian Lyles (brianmlyles).
(Merged by Junio C Hamano -- gitster -- in commit 17381ab, 03 Apr 2024)

cherry-pick: add --empty for more robust redundant commit handling

Signed-off-by: Brian Lyles

As with git-rebase(1) and git-am(1), git-cherry-pick(1) can result in a commit being made redundant if the content from the picked commit is already present in the target history.
However, git-cherry-pick(1) does not have the same options available that git-rebase(1) and git-am(1) have.

There are three things that can be done with these redundant commits: drop them, keep them, or have the cherry-pick stop and wait for the user to take an action.
git-rebase(1) has the --empty option added in commit e98c426 ("rebase (interactive-backend): fix handling of commits that become empty", 2020-02-15, Git v2.26.0-rc0 -- merge listed in batch #8), which handles all three of these scenarios.
Similarly, git-am(1) got its own --empty in 7c096b8 ("am: support --empty= to handle empty patches", 2021-12-09, Git v2.35.0-rc0 -- merge listed in batch #7).

git-cherry-pick(1), on the other hand, only supports two of the three possiblities: Keep the redundant commits via --keep-redundant-commits, or have the cherry-pick fail by not specifying that option.
There is no way to automatically drop redundant commits.

In order to bring git-cherry-pick(1) more in-line with git-rebase(1) and git-am(1), this commit adds an --empty option to git-cherry-pick(1).
It has the same three options (keep, drop, and stop), and largely behaves the same.
The notable difference is that for git-cherry-pick(1), the default will be stop, which maintains the current behavior when the option is not specified.

Like the existing --keep-redundant-commits, --empty=keep will imply --allow-empty.

The --keep-redundant-commits option will be documented as a deprecated synonym of --empty=keep, and will be supported for backwards compatibility for the time being.

git cherry-pick now includes in its man page:

previous commit will cause the cherry-pick to fail. To force the
inclusion of those commits, use --empty=keep.

git cherry-pick now includes in its man page:

--empty=(drop|keep|stop)

How to handle commits being cherry-picked that are redundant with
changes already in the current history.

--
drop;;
The commit will be dropped.
keep;;
The commit will be kept. Implies --allow-empty.
stop;;
The cherry-pick will stop when the commit is applied, allowing
you to examine the commit. This is the default behavior.

Note that --empty=drop and --empty=stop only specify how to handle a
commit that was not initially empty, but rather became empty due to a previous
commit. Commits that were initially empty will still cause the cherry-pick to
fail unless one of --empty=keep or --allow-empty are specified.

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