Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

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?

like image 539
Craig Otis Avatar asked Aug 11 '14 23:08

Craig Otis


People also ask

What happens if you get a conflict during a merge?

Merge conflicts happen when you merge branches that have competing commits, and Git needs your help to decide which changes to incorporate in the final merge. Git can often resolve differences between branches and merge them automatically.


2 Answers

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.

like image 90
fouronnes Avatar answered Oct 08 '22 06:10

fouronnes


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

like image 31
max630 Avatar answered Oct 08 '22 04:10

max630