Craig Otis
Craig Otis

Reputation: 32094

Git merge strategy 'theirs' is not resolving modify/delete conflict

When performing a git merge with the following options:

git merge -X theirs master

There are occasionally conflicted files like so:

CONFLICT (modify/delete): File_A.java deleted in master and modified in HEAD. Version HEAD of File_A.java left in tree.

However, I would like for the -X theirs option to be recognized in these cases, and use the theirs version of the change, which is for the file to be deleted.

Is there a reason this type of conflict is not automatically resolved, especially since I'm providing a specific merge strategy that suggests it should remove the file?

Further, how (if possible) can I update my merge command to use the theirs version of this type of conflict?

Upvotes: 46

Views: 8782

Answers (3)

fouronnes
fouronnes

Reputation: 4038

A bit late but might be useful, you can resolve this type of conflict with:

git merge -X theirs master
git diff --name-only --diff-filter=U | xargs git rm

Basically it means "delete all unmerged files" during the conflict resolution.

Upvotes: 28

max630
max630

Reputation: 9248

Looks like theirs option of recursive strategy (this is what you actually use, see the [1]) does not affect tree merging, it is used only for file content merging when both files modified only. I don't really know if there is any merge command option which can do what you want. You could try to make a script which scans conflicted files (with git status --porcelain) and then either removes the file (git rm --force <file>) or get the remote version of it (git checkout --theirs <file>)

[1] https://www.kernel.org/pub/software/scm/git/docs/git-merge.html#_merge_strategies

Upvotes: 9

CodeWizard
CodeWizard

Reputation: 142432

Further, how (if possible) can I update my merge command to use the theirs version of this type of conflict?

You will need to use Merge Drivers.
You will need to create your own driver and confutation in the .gitattribute file.


Here is a list of related Q which might be helpfully to you.
Each one attach this issue forma different angle

Upvotes: 0

Related Questions