0

Let's say I have a git repository with two or more branches. In branch a I deleted some files:

Branch B (branched off branch A):

git rm fileA.txt 
git rm fileB.txt

Now we made a lot of changes in branch A. Some of these changes were done in fileA.txt and/or fileB.txt. We have to merge branch A into branch B because we need all changes. Now I got conflict with fileA.txt and/or fileB.txt:

CONFLICT (modify/delete): fileA.txt ...

This ist normal git behaviour. But I don't want that on every merge form branch A into branch B I get these conflicts. It should automaticly accept the deletion of these files.

How can this be done?

Regards, Sascha

  • This is possibly the answer you're looking for https://stackoverflow.com/questions/10697463/resolve-git-merge-conflicts-in-favor-of-their-changes-during-a-pull – Miguel Ortiz Jun 14 '18 at 14:08
  • @MiguelOrtiz: no, `-X theirs` means that when resolving conflicts *within* files, use their changes, but it has no effect on these higher level (tree) conflicts. – torek Jun 15 '18 at 00:16

1 Answers1

0

You cannot tell Git to prefer the file deletion during the git merge run.

What you can do is automate the cleaning up of the mess Git leaves behind when the auto-merge fails, as after these modify/delete conflicts.

See my answer to a related question: git rebase conflicts, how to delete all conflicting files that were deleted in the HEAD.

As there, files that you deleted, but they modified, in your HEAD commit and in their tip commit, as compared to the merge base commit, will not exist at stage 2 in the index, but will exist at stages 1 and 3.

Files that they deleted, but that you modified, will exist at stages 1 and 2, but not at stage 3.

You can read through the entire index contents, noting which files exist at which stages. From this, you should determine which files you wish to delete after all. Use git rm to delete them (from all index stages in which they exist, and from the work-tree) and you have resolved those conflicts. If you write a program to do this, you will have this part all automated:

git checkout <branch>             # set up your HEAD
git merge <other>                 # start the merge, which gets conflicts
program-to-clean-up-the-index     # do file-deletions automatically
git status                        # see what's left to do
...                               # do whatever is required
git commit                        # finish the merge
torek
  • 330,127
  • 43
  • 437
  • 552