How to Conclude a Git Cherry-Pick?
Asked Answered
G

5

87

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 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!

Glycoside answered 13/9, 2012 at 0:14 Comment(4)
What git version are you using? git cherry-pick --continuehas been introduced in August 2011 (github.com/git/git/commit/…, git1.7.7+)Relate
@VonC, you should submit this as an answer. It is now the correct one.Suberin
@Suberin I have posted it as an answer below.Relate
I've asked this question in Spanish here without having read this one before.Pareto
G
19

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

Glycoside answered 13/9, 2012 at 1:8 Comment(4)
Why the down vote? It worked for me just fine and hasn't caused any problems.Glycoside
Sure, this will work for most people, however it's an example of some worst-practices and could be catastrophic for some people.Dermoid
For my case, I use SourceTree and did cherry pick by mistake. It didn't commit anything and a class conflicted with merge. I discarded it. Then I wanted to pull some commits. The pull failed. I tried your code but it didn't work. That's because you got some downvotes.Pathological
this works too https://mcmap.net/q/237539/-how-to-conclude-a-git-cherry-pick and is way saferReminiscence
B
182

Next time try git cherry-pick --abort, otherwise what you did should more or less work.

Borrowing answered 13/9, 2012 at 13:52 Comment(0)
G
19

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

Glycoside answered 13/9, 2012 at 1:8 Comment(4)
Why the down vote? It worked for me just fine and hasn't caused any problems.Glycoside
Sure, this will work for most people, however it's an example of some worst-practices and could be catastrophic for some people.Dermoid
For my case, I use SourceTree and did cherry pick by mistake. It didn't commit anything and a class conflicted with merge. I discarded it. Then I wanted to pull some commits. The pull failed. I tried your code but it didn't work. That's because you got some downvotes.Pathological
this works too https://mcmap.net/q/237539/-how-to-conclude-a-git-cherry-pick and is way saferReminiscence
R
18

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.

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)

cherry-pick: fix --quit not deleting CHERRY_PICK_HEAD

--quit is supposed to be --abort but without restoring HEAD.
Leaving CHERRY_PICK_HEAD behind could make other commands mistake that cherry-pick is still ongoing (e.g. "git commit --amend" will refuse to work). Clean it too.

For --abort, this job of deleting CHERRY_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.

Relate answered 21/8, 2018 at 21:38 Comment(4)
Even though git cherry-pick --continue does not work, git cli still recommends that to me. git cherry-pick --quit works just fine.Fusionism
@AmoghJahagirdar What version of Git are you using?Relate
git version 2.21.0.windows.1Fusionism
@AmoghJahagirdar Can you check if the issue persists with Git For Windows 2.27? (github.com/git-for-windows/git/releases)Relate
R
8

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

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

These days (2014), that would be the command to use when you see "You have not concluded your cherry-pick".

Relate answered 5/8, 2014 at 12:13 Comment(0)
R
1

Another option: with Git 2.23 (Q3 2019), a git cherry-pick --continue will actually work!

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.

See commit e981bf7 (01 Jul 2019) by Phillip Wood (phillipwood).
(Merged by Junio C Hamano -- gitster -- in commit 8a4acc5, 19 Jul 2019)

git-prompt: improve cherry-pick/revert detection

If 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 or revert is in progress, if the user has committed a conflict resolution with 'git commit' in the middle of a sequence of picks or reverts then CHERRY_PICK_HEAD/REVERT_HEAD will not exist so we have to read the todo file.

Relate answered 21/7, 2019 at 3:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.