当不进行樱桃采摘时,之前的樱桃采摘现在为空
我正在尝试使用 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
我不是樱桃选择并且不确定为什么我会收到要跳过的错误。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
发生这种情况是因为您没有做您认为正在做的事情:
当您退出而不修改该文件时,您实际上仍在进行变基。 如果您想退出而不进行变基,您应该删除文件中的所有行(或至少删除包含提交的每一行),然后保存并退出。这将显示错误并中止变基。
退出通常会起作用,而似乎什么也不做,是因为当你的历史记录是线性的时,默认情况下,如果没有任何关于提交的信息,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:
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).
您可能需要
git rebase - -empty(=drop|keep|ask)
选项:这特别有用(现在是 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 日)gitcherry-pick
现在包含在其 手册页:gitcherry-pick
现在包含在其 手册页:You might need to
git rebase --empty(=drop|keep|ask)
option:This is especially useful (now Q2 2024) because the
git cherry-pick
done in the background bygit 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 forgit-rebase
(1) andgit-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)git cherry-pick
now includes in its man page:git cherry-pick
now includes in its man page: