1

I had git merge conflicts after deleting some files (on OSX) and ran:

git mergetool

After running through most of the conflicts, I accidentally deleted a local file I meant to keep:

Deleted merge conflict for 'app/xxxapp/xxxapp/AppDelegate.swift':
  {local}: created file
  {remote}: deleted
Use (c)reated or (d)eleted file, or (a)bort? d

Is there any way to recover the file?

1 Answer 1

1

Yes: after git mergetool finishes (or in another window), run:

git checkout --ours app/xxxapp/xxxapp/AppDelegate.swift
git add app/xxxapp/xxxapp/AppDelegate.swift

The first command extracts the HEAD version of the file into the work-tree, and the second tells Git that this is the correct resolution (vs what you already told Git through git mergetool: that the correct resolution was to discard the file).

You can also or instead use:

git checkout HEAD app/xxxapp/xxxapp/AppDelegate.swift

The latter has the advantage of marking the item resolved all in one command.

Not the answer you're looking for? Browse other questions tagged or ask your own question.