git: unable to cherry pick

4.5k views Asked by At

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

2

There are 2 answers

6
Igal S. On

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
0
James Fry On

Upgrading to homebrew git 2.11.1 fixed the issue for me.

Based on the output messages and the dialogue on this pull request for git-for-windows which was subsequently raised upstream, and this mailing list thread it appears for some reason the return value from refresh_cache_entry() is null which causes the segmentation fault (in my case the paths I was cherry-picking onto do not exist on the branch I am on)

Here's what happened for me:

$ git cherry-pick d4c26fc1
Segmentation fault: 11

$ git cherry-pick --abort
error: no cherry-pick or revert in progress
fatal: cherry-pick failed

$ rm .git/index.lock

$ brew upgrade git
Updating Homebrew...
...
==> Summary
  /usr/local/Cellar/git/2.11.1: 1,456 files, 32.4M

$ git cherry-pick d4c26fc1
error: addinfo_cache failed for path 'foo/bar/baz'
error: could not apply d4c26fc... Some commit subject
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'