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?
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With