Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Fatal: cherry-pick failed' with Git

I was working on a branch X. I made a commit and pushed it.

Then I wanted to cherry-pick it to branch Y. But due to some unmerged files present, I got the following message:

error: 'cherry-pick' is not possible because you have unmerged files. hint: Fix them up in the work tree, hint: and then use 'git add/rm <file>' as hint: appropriate to mark resolution and make a commit, hint: or use 'git commit -a'. fatal: cherry-pick failed 

Now, I just want to delete my branch Y, then re-create the branch Y and then want to manually edit the file where I was trying to cherry-pick.

Currently, I'm unable to delete the branch as it is my working branch. I cannot checkout any other branch. I'm getting the following error on trying to change the branch.

mod/assign/locallib.php: needs merge error: you need to resolve your current index first 

I just need to delete the branch Y, without losing anything on branch X.

EDIT #1

I edited the file mod/assign/locallib.php

On doing git status, I get:

# On branch MDL-38267_24 # Unmerged paths: #   (use "git add/rm <file>..." as appropriate to mark resolution) # #   both modified:      mod/assign/locallib.php # 

What file should I add in git add .. ?

like image 695
xan Avatar asked May 08 '13 14:05

xan


People also ask

How do you fix cherry pick conflict?

One possible way to avoid these cherry-pick conflicts is by doing the cherry-picking in the order of oldest commit to latest commit, i.e. based on commit date.

How do you end a cherry pick?

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.

How do you cherry pick a commit from another branch Intellij?

Apply a commit to another branchOpen the Git tool window Alt+9 and switch to the Log tab. Locate the commit containing the changes you want to cherry pick. on the toolbar). Select the required commit.

What is cherry pick in Git?

Git Cherry Pick git cherry-pick is a powerful command that enables arbitrary Git commits to be picked by reference and appended to the current working HEAD. Cherry picking is the act of picking a commit from a branch and applying it to another. git cherry-pick can be useful for undoing changes.

How do I fix Git cherry-pick error?

To fix the error, apply the $ git cherry-pick --quit command which will take you back to the feature branch without any commits history. From here you can apply the git log command to see the available commits then correctly choose one. You may also opt to perform a new commit depending on the changes that you desire.

What is the difference between --continue and --quit in Git cherry pick?

--continue: Facilitates continuity of an operation after successful resolution of a cherry-pick conflict --quit: Resets the git cherry-pick operation back to the active branch in the directory for a failed cherry-pick conflict. Cherry pick is a great command to utilize in the git environment but you have to take a lot of precautions when using it.

Why can't I cherry-pick a commit from a deleted branch?

That is because you don't have the remote branch (from where you want to cherry-pick) locally Show activity on this post. Just deleting a branch does not remove any commits. Immediately afterwards, any git command will work when given the SHA hash of a commit that was on the deleted branch.


2 Answers

Since you have already edited the conflict file, you just need

git add mod/assign/locallib.php 

then

git cherry-pick --continue 
like image 163
pktangyue Avatar answered Sep 22 '22 17:09

pktangyue


You attempted to do a merge (via either git merge or git pull) and have files that have conflicts that are not resolved. If you do git status, you will likely see file(s) listed as being 'changed by both'. You need to take care of this before you do anything else.

Do git mergetool and it will bring up the files one at a time. Fix the file so that the conflicts are resolved and then you should be able to proceed.

like image 34
Schleis Avatar answered Sep 26 '22 17:09

Schleis