如何结束 Git Cherry-Pick?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12397752/
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
How to Conclude a Git Cherry-Pick?
提问by Stunner
Yesterday I cherry-picked two commits into my main branch, one of them caused merge conflicts and I resolved them, committed and pushed them to origin. Today I am attempting to pull from the server when I get the following error:
昨天我挑选了两个提交到我的主分支,其中一个导致了合并冲突,我解决了它们,提交并将它们推送到源。今天,当我收到以下错误时,我试图从服务器中拉取:
$ git pull
fatal: You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists).
Please, commit your changes before you can merge.
$
Git status reads:
Git 状态显示:
$ git status
# On branch main
# Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.
#
$
I have tried the following to no avail:
我尝试了以下方法无济于事:
$ git cherry-pick --continue
usage: git cherry-pick [options] <commit-ish>
$
Any idea on how I could resolve this? Thanks in advance!
关于如何解决这个问题的任何想法?提前致谢!
采纳答案by Stunner
Solved with the following: rm .git/CHERRY_PICK_HEAD
I realize this is dangerous as this doesn't guarantee internal consistency within git, but no issues for me so far...
解决了以下问题:rm .git/CHERRY_PICK_HEAD
我意识到这很危险,因为这不能保证 git 内部的一致性,但到目前为止对我来说没有问题......
回答by Christopher
Next time try git cherry-pick --abort
, otherwise what you did should more or less work.
下次试试git cherry-pick --abort
,否则你所做的应该或多或少会奏效。
回答by VonC
If the git cherry-pick --continue
doesn't work, that means git is too old: that option was introduced for git 1.7.8 (Dec. 2011) in commit 5a5d80f
如果git cherry-pick --continue
不起作用,则意味着 git 太旧了:该选项是在commit 5a5d80f 中为 git 1.7.8(2011 年 12 月)引入的
It works by dropping the first instruction from .git/sequencer/todo and performing the remaining cherry-picks listed there, with options (think "
-s
" and "-X
") from the initial command listed in ".git/sequencer/opts
".
它的工作原理是从 .git/sequencer/todo 中删除第一条指令并执行那里列出的剩余樱桃选择,
-s
并使用“-X
”中列出的初始命令中的选项(想想“ ”和“ ”).git/sequencer/opts
。
These days (2014), that would be the command to use when you see "You have not concluded your cherry-pick
".
这些天(2014 年),这将是您看到“ You have not concluded your cherry-pick
”时使用的命令。
回答by VonC
Since my previous answer from 2014, the proper command nowadays (2018) is git cherry-pick --quit
.
And before Git 2.19 (Q3 2018), "git cherry-pick --quit
" failed to remove CHERRY_PICK_HEAD
even though we won't be in a cherry-pick session after it returns, which has been corrected.
自从我从 2014 年开始回答以来,现在(2018 年)正确的命令是git cherry-pick --quit
.
在 Git 2.19(2018 年第 3 季度)之前,“ git cherry-pick --quit
”未能删除,CHERRY_PICK_HEAD
即使我们不会在它返回后进入挑选会议,这已得到纠正。
See commit 3e7dd99(16 Aug 2018) by Nguy?n Thái Ng?c Duy (pclouds
).
(Merged by Junio C Hamano -- gitster
--in commit 39e415c, 20 Aug 2018)
请参阅Nguy?n Thái Ng?c Duy ( ) 的commit 3e7dd99(2018 年 8 月 16 日)。(由Junio C Hamano合并-- --在commit 39e415c,2018 年 8 月 20 日)pclouds
gitster
cherry-pick: fix --quit not deleting CHERRY_PICK_HEAD
--quit
is supposed to be--abort
but without restoringHEAD
.
LeavingCHERRY_PICK_HEAD
behind could make other commands mistake thatcherry-pick
is still ongoing (e.g. "git commit --amend
" will refuse to work). Clean it too.For
--abort
, this job of deletingCHERRY_PICK_HEAD
is on "git reset
" so we don't need to do anything else. But let's add extra checks in--abort
tests to confirm.
樱桃挑选:修复 --quit 不删除 CHERRY_PICK_HEAD
--quit
应该是--abort
但没有恢复HEAD
。
留下CHERRY_PICK_HEAD
来可能会导致其他cherry-pick
仍在进行中的命令错误(例如“git commit --amend
”将拒绝工作)。也清洗一下。对于
--abort
,删除工作CHERRY_PICK_HEAD
在“git reset
”上,所以我们不需要做任何其他事情。但是让我们在--abort
测试中添加额外的检查来确认。
回答by VonC
Another option: with Git 2.23 (Q3 2019), a git cherry-pick --continue
will actually work!
另一种选择:使用 Git 2.23(2019 年第 3 季度),agit cherry-pick --continue
将真正起作用!
When one step in multi step cherry-pick or revert is reset or committed, the command line prompt script failed to notice the current status, which has been improved.
多步cherry-pick或revert中的一步reset或commit时,命令行提示脚本没有注意到当前状态,已改进。
See commit e981bf7(01 Jul 2019) by Phillip Wood (phillipwood
).
(Merged by Junio C Hamano -- gitster
--in commit 8a4acc5, 19 Jul 2019)
请参阅Phillip Wood ( )提交的 e981bf7(2019 年 7 月 1 日)。(由Junio C Hamano合并-- --在8a4acc5 提交中,2019 年 7 月 19 日)phillipwood
gitster
git-prompt
: improvecherry-pick
/revert
detectionIf the user commits or resets a conflict resolution in the middle of a sequence of cherry-picks or reverts then
CHERRY_PICK_HEAD
/REVERT_HEAD
will be removed and so in the absence of those files we need to check.git/sequencer/todo
to see if there is a cherry-pick or revert in progress.See if a
cherry-pick
orrevert
is in progress, if the user has committed a conflict resolution with 'git commit
' in the middle of a sequence of picks or reverts thenCHERRY_PICK_HEAD
/REVERT_HEAD
will not exist so we have to read thetodo
file.
git-prompt
:改进cherry-pick
/revert
检测如果用户在一系列挑选或恢复的中间提交或重置冲突解决方案,则
CHERRY_PICK_HEAD
/REVERT_HEAD
将被删除,因此在没有这些文件的情况下,我们需要检查.git/sequencer/todo
是否有挑选或恢复进步。查看 a
cherry-pick
或revert
是否正在进行中,如果用户git commit
在一系列选择或还原的中间提交了与“ ”的冲突解决方案,则CHERRY_PICK_HEAD
/REVERT_HEAD
将不存在,因此我们必须读取todo
文件。