3

I'm trying to merge from a source branch that has deleted some of the files that've been modified in the target branch. I want to ignore the deletions and simply accept what the destination branch already has.

When I:

git merge -s recursive -X ours master

the output of git status is:

# On branch nyap-artifactory
# Changes to be committed:
#
#   new file:   file-re-added-by-source-branch-that-should-be-deleted
#   modified:   file-modified-by-source-branch
#
# Unmerged paths:
#   (use "git add/rm <file>..." as appropriate to mark resolution)
#
#   deleted by them:    file-deleted-by-source-branch-that-should-be-kept

What's the next step?

Noel Yap
  • 18,822
  • 21
  • 92
  • 144

2 Answers2

2

You should just re-add the file to the index:

git checkout HEAD -- file-deleted-by-source-branch-that-should-be-kept

and commit the merge.

What this does is get the latest version from the nyap-artifactory branch. [*]


[*] (A git reset -- file-deleted-by-source-branch-that-should-be-kept might be enough, but is a bit trickier to work with, since it doesn't necessarily update the working tree, and has options that are powerful enough to accidentally lose data).

sehe
  • 374,641
  • 47
  • 450
  • 633
1

git add file-name and the commit the merge. Similar question here with further explanation: git - merge conflict when local is deleted but file exists in remote

Community
  • 1
  • 1
Keith
  • 686
  • 5
  • 7
  • 3
    Keith, if you can't spare the time to actually explain things, it's more suitable as a comment – sehe May 10 '13 at 17:51
  • 1
    I apologize. Will follow that advice for now on, but was actually unable to leave comments until the reputation awarded for last answer – Keith May 10 '13 at 18:09
  • good point, I keep forgetting about those 'privileges' :) Welcome to SO as a contributor! – sehe May 10 '13 at 18:40