Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git: unable to cherry pick

I am caught up in a weird loop while trying to cherry pick. Here is what I do, and where the problem is.

I have two branches: mainline, and temp. I want to cherry-pick a specific commit from mainline to temp. I am doing this like follows.

  1. git checkout temp
  2. git cherry pick <commit sha>
  3. Now, I get: Segmentation fault: 11
  4. I rerun the command from 2), and get: Unable to create ...git/index.lock': File exists

    ====================================================================

  5. Now I run rm -f ./.git/index.lock

  6. Try again git cherry pick <commit sha>

  7. Now I get this:

    error: The following untracked working tree files would be overwritten by merge: myfile.java

... for a file which isn't even there. I had it before, but I renamed it, so file under that name is not in a repository.

  1. I run git status and now I see the file myfile.java under untracked files. And now it even appears in the editor. I can delete it from the editor, but can't delete it from git repository. I get pathspec 'myfile.java' did not match any files
  2. OK, so I delete the file from editor, rerun cherry-pick and I am back to step 3).

What is happening here, and how can I just do my cherry-pick? :D

like image 794
wesleyy Avatar asked Jan 08 '17 11:01

wesleyy


People also ask

Why is my cherry pick empty?

It's exactly what it says: the changes you're trying to cherry-pick are already wholly contained in the branch you're on. I.e. the result of the cherry-pick is no changes. You can create an empty commit with the --allow-empty flag to indicate that you attempted to cherry-pick, but there were no changes to pull in.

How do I continue git cherry pick?

If you look at the console, "fix conflicts and run "git cherry-pick --continue." When fixing conflicts the normal way (without the cherry-pick), the console will mention to commit (after the conflicts have been fixed).

Can you cherry pick a squashed commit?

as long as you have the hash of the commit, you can cherry-pick it.


1 Answers

I don't know why you have a segmentation fault. I suggest to make sure you work with the latest git version.

A different way to cherry pick would be to create a patch from the commit and apply it:

git checkout temp
git format-patch -1 <commit sha>
git apply 0001.....patch
like image 88
Igal S. Avatar answered Oct 06 '22 00:10

Igal S.