6

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

MD XF
  • 7,860
  • 7
  • 40
  • 71
wesleyy
  • 2,575
  • 9
  • 34
  • 54

2 Answers2

1

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
Igal S.
  • 13,146
  • 5
  • 30
  • 48
  • The segmentation fault is the least of my problems. If I just rerun the command, it goes away but different error appears (step 4.). Not sure what patch is, I have never used that. – wesleyy Jan 08 '17 at 12:03
  • A patch file is just a text file containing the changes of the commit. Similar output to `git diff`. Then git knows how to apply the patch on your working directory. – Igal S. Jan 08 '17 at 12:09
  • And what is this 0001... ? – wesleyy Jan 08 '17 at 12:14
  • 1
    This solution can work, since it avoids using cherry pick, which seems the problem. – fedepad Jan 08 '17 at 12:14
  • 1
    @wesleyy The 0001...patch is the generated patch file from the previous `git format-patch` command. – fedepad Jan 08 '17 at 12:15
  • 2
    @wesleyy The segmentation fault is the first of your problems. The other problems are just consequences of it. As you state yourself: when you have fixed the latter, you are back at the former. Perhaps you want to bring the matter to the git mailing list. Just write to `git@vger.kernel.org`. Be sure to include the output of `GIT_TRACE=2 git cherry-pick that-commit-sha1` and include the version you are using (`git version`). – j6t Jan 09 '17 at 06:20
0

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'
James Fry
  • 1,133
  • 1
  • 11
  • 28