148

My git cherry-pick FOO produced a conflict.

I could go through the conflicting files and delete the lines between <<<<<<< and =======, and the conflict markers themselves, but I'm hoping there's an easier way.

I think the svn equivalent was choosing theirs-conflict to resolve.

How do I do this in git?

I don't want git checkout --theirs <file> as that seems to produce the same result as git checkout foo <file> instead of just getting git diff FOO~..FOO <file> applied.

antak
  • 19,481
  • 9
  • 72
  • 80

1 Answers1

273

First you should undo your cherry-pick, try to run this

git cherry-pick --abort

Second, try to make cherry-pick, but in this time you get their changes not yours, so make this:

git cherry-pick --strategy=recursive -X theirs {Imported_Commit}
Flimm
  • 136,138
  • 45
  • 251
  • 267
elhadi dp ıpɐɥןǝ
  • 4,763
  • 2
  • 30
  • 34
  • 6
    A bit more information about what those switches are doing is available at http://stackoverflow.com/questions/2268172/git-merge-recursive-theirs-how-does-it-work – antak Jan 17 '13 at 22:28
  • 38
    I tried this exactly: `git cherry-pick --strategy=recursive -X theirs 1b92440` and I'm still prompted for an unresolved conflict: `Unmerged paths: deleted by them: (file path)`. Any idea? – pilau Aug 02 '13 at 10:41
  • A more understandable way to reset after a failed cherry-pick/merge is to use `git reset --merge` – Pylinux Oct 04 '13 at 17:54
  • 13
    `git cherry-pick --abort` - this is recommended way to undo cherry-pick operation. – tommyk May 05 '14 at 08:35
  • I don't have a `-X` option in `git cherry-pick`. git 1.7.2.3. – Frank Jul 30 '14 at 05:55
  • @Frank: this is strange, look at https://www.kernel.org/pub/software/scm/git/docs/git-cherry-pick.html you will see the option -X and its use – elhadi dp ıpɐɥןǝ Aug 08 '14 at 14:02
  • If you still get a conflict, you can resolve the conflicts manually and then run `git cherry-pick --continue` – Motin Apr 10 '18 at 09:31
  • didn't work for me, same *umerged paths*, conflict is in deleting files that differ – sebkraemer Sep 22 '20 at 09:45
  • 2
    AFAICS, `--strategy=recursive` is default unless you configured something else. Leaving it out will shorten the cmd considerably. – sebkraemer Sep 22 '20 at 09:56
  • It also was not really working for me. I resolved it by doing `git rm file1 file2 ...` – flix Feb 22 '21 at 14:01
  • Doesn't `-Xtheirs` actually accept "our" changes instead of "their" changes. IOW, doesn't it work like `merge` or `rebase`? – Chris F Apr 29 '21 at 17:02